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

13 Answers

13

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);
        }
    }

I'm using the 2018 version and just saw this message (newbie). What should I do with this code?

@kleber-swf explained it good in his post : 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. So create the file PostBuildActions and post the above code inside and normally when you will build your Webgl, no more mobile warning ! Right like that ? :-)

And if some of the questions helped you, help the community back and give them an up vote. This will make the life of the next people who look for the same answer easier. Cheers!

In Unity 2019.3.0a3 when WebGL Building I get an error: The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)

For Unity 2019 replace: [PostProcessBuild] with: [PostProcessBuildAttribute(1)] It works for me, I'm in v2019.3.0a3. Cheers!

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();
    },

Worked for me - thanks.

Can confirm, this works for 2019 version of Unity aswell. Thank you!

if u like and have " any desk" app installed or u can install send your id to my gmail so i can take a look : savajjad@gmail.com

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

Thanks.. I can now skip the message :)

It seems UnityLoader.js is generated each time - is there a way to have this mod be persistent?

See below for the PostProcess version or edit the original files under where Unity gets them for the builds.

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.

Thank you so mucho!!! Work for me in Unity 2017.2.1f1 Thank you again.

у меня тоже это работает в 2019.4

still working in unity 2019.2.3f1

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(){}

Hi, This isn't working. I also tried deleting the compatibilityCheck from UnityLoader.js I'm on Unity 2017.1.0f3 Personal

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.

This worked for me in 2019.3.0a3. Don't forget to not only patch UnityLoader.js but also re-minify this file to UnityLoader.min.js There are plenty online minifiers but not all did work for me, this one did: https://skalman.github.io/UglifyJS-online/

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.

I switched out the functions because otherwise OnBeforeSerialize() will mostly be called even when you dont edit anymore which is resource consoming. The bool makes sure it will be called on the first time unity serialized this property, so this acts like a default value for single class fields like Test testInt above. If you leave the bool out, it will be resetted back to 500 everytime you want to reassign the value in the inspector.

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.

This is the best answer when you are dealing with more complex data like arrays and classes, I don't even know why I didn't think of this. Just parsing it to and from JSON with JsonUtility.

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);
    }
}

I still have some old projects on 2021.3.15f1. In index.html I edited unityShowBanner(‘…’); text to keep the warning but add a clarifier that the game may still run. I assume you can just comment out that line so no warning shows up, but I haven’t tried it yet.