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

4
  • 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.
    – user5294349
    Oct 27, 2015 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 ) Oct 28, 2015 at 12:46
  • I don't know what expected behaviour is; but you might want to check this post 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.
    – user5294349
    Oct 28, 2015 at 13:08
  • still an issue in chrome 78 (mac os)
    – schellmax
    Nov 12, 2019 at 14:50

1 Answer 1

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!")
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.