Unity WebGL Disable mobile warning

Hi,

I would like to disable the default warning: “Please note that Unity WebGL is not currently supported on mobiles.”

Does anyone know if it’s possible?

In the Unity Forums the user “jonas-echterhoff” wrote that you could deactivate the message.
https://forum.unity3d.com/threads/webgl-for-mobile-devices.291068/#post-1921583

Thanks and have a nice day,
Jordan Kniest

Hi here is a new version that is working with the 2018 version :slight_smile:

using System;
    using System.IO;
    using System.Text.RegularExpressions;
    using UnityEditor;
    using UnityEditor.Callbacks;
    
    public class PostBuildActions
    {
        [PostProcessBuild]
        public static void OnPostProcessBuild(BuildTarget target, string targetPath)
        {
            var path = Path.Combine(targetPath, "Build/UnityLoader.js");
            var text = File.ReadAllText(path);
            text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
            File.WriteAllText(path, text);
        }
    }

To understand what exactly goes with the js script, format it first, mine was completely not formatted. I used this jsbeautifier.org. Anyways, all you have to do is the following to by pass the warning. For your clarity i’m attaching my UnityLoader.js as well.

compatibilityCheck: function(e, t, r) {
        t();
    },

The message is part of the UnityLoader.js file and you can just edit that to whatever you want with a text editor.

Based on @kart_ranger 's answer, I made a small class to handle it automatically after the build is done:

using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;

public class PostBuildActions {
	[PostProcessBuild]
	public static void OnPostProcessBuild(BuildTarget target, string targetPath) {
		var path = Path.Combine(targetPath, "Build/UnityLoader.js");
		var text = File.ReadAllText(path);
		text = Regex.Replace(text, @"compatibilityCheck:function\(e,t,r\)\{.+,Blobs:\{\},loadCode",
			"compatibilityCheck:function(e,t,r){t()},Blobs:{},loadCode");
		File.WriteAllText(path, text);
	}
}

Just create a file PostBuildActions.cs inside any Editor folder and execute your build normally. It will replace the problematic function with the proposed solution.

Please keep in mind that this code could be incompatible with future versions of Unity WebGL build. It was tested on Unity Editor 2017.3.0f3

Hello everyone, this works for me in 2019.2.4 :

UnityLoader.compatibilityCheck=function(e,t,r){t();};

in the index.html file , right before the unityloader instantiate line.

If you don’t want to mess around with the Unity Loader source, you can simply do this before the new GameInstance is created in your index.html.

//turn off unity's annoying alert() dialog.
UnityLoader.Error.handler = function(){}

If you are on Windows, open the following folder:

<unity_installation_folder>\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools

Here, you will find two files : UnityLoader.js and UnityLoader.min.js

Based on the previous answers, remove the JS code responsible for popping up the warnings and each time you will build for WebGL the previous files (now, without the warning) will be copied to the final build.

Cheers.

Created a version based on Skylabs answer, that handles new functionality for 2019.3 and only runs for webGL builds: https://gist.github.com/JohannesDeml/f551b1e60c59e8472c3e843014d7bd10

I tried the solutions of @kart_ranger , @kleber-swf , @Skylabs and @TheRoccoB . They all made sense to me, but none of them worked. Is it possible that Unity added something that is actually calling for the warning message via an HTTP URL request?[132526-unityloader.txt|132526]

EDIT: I added my UnityLoader from my latest attempt. Changed the extension to .txt as this message board doesn’t allow .js attachments.

Try please:

1_ Find folder: Progam file / Unity / Editor / Data / PlaybackEngines / WebGLSupport / BuildTools

2_ Open and copy all the content of these scripts:

  UnityLoader.js
  UnityLoader.min.js

and paste in a txt document.

3_ Comment or delete code lines…

var UnityLoader = UnityLoader || {
  /*compatibilityCheck: function (gameInstance, onsuccess, onerror) {
    if (!UnityLoader.SystemInfo.hasWebGL) {
      gameInstance.popup("Your browser does not support WebGL",
        [{text: "OK", callback: onerror}]);
    } else if (UnityLoader.SystemInfo.mobile) {
      gameInstance.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.",
        [{text: "OK", callback: onsuccess}]);
    } else if (["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1) {
      gameInstance.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.",
        [{text: "OK", callback: onsuccess}]);
    } else {
      onsuccess();
    }*/

    t();

  },
  Blobs: {},

4_ Add t(); instead in both script.

5_Save and replace these scripts.

6_ in index.html add:

UnityLoader.compatibilityCheck=function(e,t,r){t();};

right before the unityloader instantiate line.

7_ Build and run.

Sorry for my English. It works in unity 2017.2.1f1.
Thank you all for helping to resolve this issue.

index.html:

<script>
  UnityLoader.compatibilityCheck = function (e, t) {t();}; // <== add this line
  var unityInstance = UnityLoader.instantiate("unityContainer", "Build/WebOut.json", {onProgress: UnityProgress});
</script>

If you are using MD5 hashes the script can’t find Build/UnityLoader.js. So this adjustment will just take the first .js file which should be the the UnityLoader.

using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;

// Disable mobile warning on webgl!
// https://answers.unity.com/questions/1339261/unity-webgl-disable-mobile-warning.html
public class PostBuildActions
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string targetPath)
    {
        string path;
        if (File.Exists(Path.Combine(targetPath, "Build/UnityLoader.js")))
        {
            path = Path.Combine(targetPath, "Build/UnityLoader.js");
        }
        else
        {
            // In case files are hashed using MD5, just take the first .js file and hope it's the UnityLoader
            var files = Directory.GetFiles(Path.Combine(targetPath, "Build/"), "*.js");
            path = files.First();
        }
        var text = File.ReadAllText(path);
        text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
        File.WriteAllText(path, text);
    }
}