3
  1. Open dev tools console.
  2. Exec this code:

    window.addEventListener("mousemove", function() { console.log("moved!") });
    
  3. Activate any another window.

  4. Move mouse into browser window (but DO NOT put focus in).
  5. Look in console.

In FF: nothing there.

In Chrome: there is one "moved!" message.

So in inactive window Chrome triggers exactly one mousemove event when mouse enters window, and then ignores any following movements.

Is this a bug?

And how to manage this? I can detect that mouse has left a browser window, with toElement prop of mouseout event. But how to detect whether window is currently active?


My env:

Chrome 46.0.2490.80

Firefox 41.0

MacOS Yosemite 10.10.5

jeron-diovis
  • 788
  • 1
  • 8
  • 19
  • What version of FF / Chrome are you using? I see exactly the same behaviour in Chrome 46.0.2490.80m and FF 41.0.1 - and in each I see multiple "moved!" messages appearing in the console when the mouse is over the inactive browser window. –  Oct 27 '15 at 12:14
  • Chrome 46.0.2490.80, Firefox 41.0. My fault, I didn't say that it's on MacOS ( Yosemite 10.10.5 ) – jeron-diovis Oct 28 '15 at 12:46
  • I don't know what expected behaviour is; but you might want to check [this post](http://stackoverflow.com/questions/9632741/javascript-is-there-any-way-to-detect-that-window-is-currently-active-i-e-is/9634295#9634295) which discusses a jQuery plugin that gives you a show/hide event that uses the new Page Visibility API or falls back to the `blur`/`focus` events where that is not available. Perhaps that will serve your needs. –  Oct 28 '15 at 13:08
  • still an issue in chrome 78 (mac os) – schellmax Nov 12 '19 at 14:50

1 Answers1

0

I am seeing the same behavior in Chrome 107 on Mac OS 13.0 Ventura. Here is my workaround.

document.addEventListener('mousemove', function(){
    if(document.hasFocus()){
        console.log("moved!")
    }
});
user1763510
  • 1,070
  • 1
  • 15
  • 28