3

Chrome only allows fullscreen by "user interaction", ie a mouseclick.

This works:

addEventListener("click", function() {
    var el = document.documentElement, 
    rfs = el.webkitRequestFullScreen;
    rfs.call(el);
});

But the following does not. Console reports "Failed to execute 'requestFullScreen' on 'Element': API can only be initiated by a user gesture."

addEventListener("mouseenter", function() {
    var el = document.documentElement, 
    rfs = el.webkitRequestFullScreen;
    rfs.call(el);
});

IMO, a mouseenter event is as legitimate a user-interaction as a click, but i guess they don't think so.

Any workaround to get fullscreen on mouseenter?

This attempt gives same error:

addEventListener("click", function() {
    var el = document.documentElement, 
    rfs = el.webkitRequestFullScreen;
    rfs.call(el);
});

document.body.click();

I'm currently researching ways to detect simulated mouse clicks, since chrome apparently is doing that.

One way is to look for mouse coordinates of zero, since a real click will usually have non-zero coordinates. The workaround for that (i think) is to use initMouseEvent, rather than a simple document.body.click();

Another way is to examine how the event is registered. The workaround would be to change how the simulated event is registered (possible?)

There are prolly more methods.

Resources: http://w3facility.org/question/javascript-how-to-check-if-mouse-click-event-is-simulated-or-is-native-non-jquery-way/

Detect if button click real user or triggered by a script

JavaScript: how to check if mouse click event is simulated or is native? (non-jquery way)

http://help.dottoro.com/ljtxvfef.php

https://softwareengineering.stackexchange.com/questions/206026/when-to-use-event-initmouseevent-for-simulating-mouse-clicks/206247#206247

thx!

Community
  • 1
  • 1
johny why
  • 2,047
  • 7
  • 27
  • 52

0 Answers0