Unity-Technologies / furioos-sdk-js

Furioos SDK for JavaScript
30 stars 14 forks source link

Request for fullscreen was denied #34

Open yanicklandry opened 3 years ago

yanicklandry commented 3 years ago

I get the following error in Firefox :

Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.

Uncaught (in promise) TypeError: Fullscreen request denied
    request https://portal.furioos.com/7f957b9e99457de541abce2bebcbe82199b1631a.js?meteor_js_resource=true:228
[...]

fullscreenerror { target: Restricted, isTrusted: true, srcElement: Restricted, eventPhase: 0, bubbles: true, cancelable: false, returnValue: true, defaultPrevented: false, composed: true, timeStamp: 127985, … }
K-MICK commented 3 years ago

Hello,

It means that you are trying to go in fullscreen mode without user interaction. You won't be able to put the user in fullscreen without it, the browser prevents you to do so.

peettee commented 3 years ago

Hi having the same issue, geting "Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.".

I use the following code (simplified)

  var fullscreenButton      = document.getElementById("fullscreenButton");  `
  fullscreenButton.onclick  = function()
  {
      if(!player) return;
      player.maximize();
  };

where "player" is the furioos player instance created with "new Player()".

Putting fullscreen switches inside onclick events usually prevents this issue, it doesnt in this case. Anything I am doing wrong here?

Edit: Using the recommended way to go fullscreen based on the mozilla documentation I was able to successfully switch to fullscreen using the code above, simply issuing the fullscreen request directly to the container provided to the players constructor as the second argument. So instead of calling maximize() I did the following:

if (!document.fullscreenElement) {
  container.requestFullscreen().catch(err => {
    alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
  });
} else {
  document.exitFullscreen();
}

where "container" was the same DOM element which I provided as the second argument to the Player constructor.

yanicklandry commented 3 years ago

Thanks @peettee , your method actually works.

I made a code to demo it, in order for Furioos support to see that there is a bug with the player.maximize() :

https://furioos-demo-fullscreen-bug.vercel.app

Source code is here : https://github.com/pipemind-com/furioos-demo-fullscreen-bug/blob/main/pages/index.js#L22-L35