Browser being forced full screen without user input

Just wondering is there is a way to force play canvas to go full screen like this code does:

{
    if(this.app.keyboard.isPressed(pc.KEY_P)) {
   this.app.graphicsDevice.fullscreen = true;
  }
   console.log('test');
};

but without needing user input?

many thanks!

Hi @Mattturner2021 ,

Unfortunately that is not possible without user input, in chrome I get “Failed to execute ‘requestFullScreen’ on ‘Element’: API can only be initiated by a user gesture.” , this mechanism is put in place so spams website cannot go full screen automatically.

4 Likes

Yes thank god for this :slight_smile:

1 Like

Hey @Mattturner2021,

Just to add on to what @Saad_Haider said, though it won’t be possible, if you want to avoid fullscreen only coming on if the user initiates an action in the game, you can bring up a quick DOM modal the moment your game loads, with a button that says “Enter Fullscreen” or similar. That way, it will not take away from the aesthetics of the game. You can read on how to initiate a particular action on the DOMContentLoaded event here - Window: DOMContentLoaded event - Web APIs | MDN.

1 Like