Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WebGL detect browser FullScreen support

Discussion in 'WebGL' started by DimensionU, Mar 23, 2016.

  1. DimensionU

    DimensionU

    Joined:
    Aug 1, 2013
    Posts:
    43
    The documentation states that "Safari cannot currently use fullscreen and cursor locking." Because of this, I need to be able to only display my SwitchToFullScreen button when a user is running my game from Firefox, Chrome or Edge and not when running in Safari. When I've researched this, the consensus is that you should not try to detect what browser is being used, but instead detect what features are supported. Going down that path, I found that you could use...

    if (
    document.fullscreenEnabled ||
    document.webkitFullscreenEnabled ||
    document.mozFullScreenEnabled ||
    document.msFullscreenEnabled
    )

    to detect whether or not the fullscreen API is supported by the browser. The problem is: Safari returns true as well.

    So how am I to present the option of a fullscreen button to a user only if the Unity WebGL content in that browser supports it?
     
  2. DimensionU

    DimensionU

    Joined:
    Aug 1, 2013
    Posts:
    43
    For now, I am just using the (not recommended) approach of detecting the browser and enabling fullscreen support in my game if Unity's docs say that browser supports it. If someone has a better solution, please share.
     
  3. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    The problem is that Safari does support fullscreen mode, BUT, it does not support keyboard input in fullscreen mode (making it unsuitable for supporting Unity). However, there is no JavaScript API to programmatically detect this. So, detecting the browser is indeed the only thing you can do (and it is what Unity does internally as well).
     
  4. DimensionU

    DimensionU

    Joined:
    Aug 1, 2013
    Posts:
    43
    @jonas echterhoff - Thanks for the explanation. Does Unity have contact with Apple's Safari team? Is there any indication this will change or are they firm in the camp that fullscreen should only be used for presentation? I wonder if the Safari Technology Preview move could have any impact on them aligning more closely to Mozilla and Google on this. Any sense?
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    We have some contacts, but I am not aware of any plans to change this. The issue is that allowing keyboard input in fullscreen mode carries a risk of exposing the user to elaborate phishing schemes where a site takes over the screen and shows a fake UI to get users to type sensitive information. Apple engineers have decided to pick security over functionality in this case and to not allow keyboard input in fullscreen mode to prevent this.