Skip to content

Instantly share code, notes, and snippets.

@JohannesDeml
Last active September 16, 2023 01:55
Show Gist options
  • Save JohannesDeml/f551b1e60c59e8472c3e843014d7bd10 to your computer and use it in GitHub Desktop.
Save JohannesDeml/f551b1e60c59e8472c3e843014d7bd10 to your computer and use it in GitHub Desktop.
Remove Unity mobile notification warning for WebGL builds

Remove warning

Unity shows the following warning on mobile devices up to Unity 2019.4: "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway." This script helps you remove this warning

Live example

To see live examples see Unity Web GL Loading Test

Logic

The script will run after the build has completed and replace the checks from all generated javascript files.

Support

  • Tested up to Unity 2020.3, but should work with any version
  • Works with Name Files as Hashes, since it looks for all js files in the Build folder
  • Only runs when building for WebGL, so you can use it for a multiplatform project

Trouble Shooting

If you still see the message, there are several reasons why this could happen

  • Make sure you included the file in an Editor folder inside your project (e.g. Assets/Editor/RemoveMobileSupportWarningWebBuild.cs)
  • Make sure you get a console log message "Removing mobile warning from YOURPATH" after the build is finished. If you don't get this message there is a problem with your integration of the script. Probably, the script is not in the Editor folder.
  • Make sure you emptied your browser cache on the device you are testing on (Android | iOS)
  • Try to open the website in private mode, might help with strage cache problems
  • Take a look at Unity Web GL Loading Test. There you can see the script in action, take a look at how the script is integrated or build the repo yourself to see how it should behave.
  • Inside you Build folder, take a look at the *.js file, and see if you can find an instance of "UnityLoader.SystemInfo.mobile". If you can still find that, the script didn't run properly.
  • If you need professional help, you can write me an email

Further Notes

  • Unity adds this note, since the builds oftentimes don't work for mobile, so oftentimes it does make sense to include the info.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs">
// Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// public@deml.io
// </author>
// --------------------------------------------------------------------------------------------------------------------
#if !UNITY_2020_1_OR_NEWER //Not needed anymore in 2020 and above
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Supyrb
{
/// <summary>
/// removes a warning popup for mobile builds, that this platform might not be supported:
/// "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway."
/// </summary>
public class RemoveMobileSupportWarningWebBuild
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
if (target != BuildTarget.WebGL)
{
return;
}
var buildFolderPath = Path.Combine(targetPath, "Build");
var info = new DirectoryInfo(buildFolderPath);
var files = info.GetFiles("*.js");
for (int i = 0; i < files.Length; i++)
{
var file = files[i];
var filePath = file.FullName;
var text = File.ReadAllText(filePath);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
Debug.Log("Removing mobile warning from " + filePath);
File.WriteAllText(filePath, text);
}
}
}
}
#endif
@gebhardt2
Copy link

Did everything as described, broke my project. After I fixed it AND removed the script from my project, every build is now with mobile warning disabled. Any idea how that happened? (Unity 2019.2.6f1)

@JohannesDeml
Copy link
Author

Did everything as described, broke my project. After I fixed it AND removed the script from my project, every build is now with mobile warning disabled. Any idea how that happened? (Unity 2019.2.6f1)

You need to be a lot more specific, if you want me to understand your problem. Could you create a repro with the problem? A quick guess of mine, is that you added the script to your project, but not inside an editor folder? That would create buil errors. Other than that, there is nothing magical happening with this scipt, is just a post process script that runs after a project is built. Havving the disabled logic after you removed the script is very strange, I guess the script is still in your project or unity does some magic with incremental builds. You could try to just delete the build folder and do a fresh build to see if it still happens.

@afkLuna
Copy link

afkLuna commented Dec 25, 2020

Hi Sir @JohannesDemi, I did this and still gets the prompt.
Created a folder Editor inside assets, copy your code and still gets error. Is there any way I can do this on UnityLoader.js? Thank you

@JohannesDeml
Copy link
Author

Hi Sir @JohannesDemi, I did this and still gets the prompt.
Created a folder Editor inside assets, copy your code and still gets error. Is there any way I can do this on UnityLoader.js? Thank you

Hi @afkLuna,
make sure you cleared your cache on your mobile test device. The script still works for unity 2020.2, you can take a look at this project to see it in action. If you want to make sure, that the script runs, take a look at your unity console. It should print "Removing iOS warning from YOUR_FILE_PATH".

@AlghaniAbdullaMsys
Copy link

Hi, I'm using an InApp browser plugin to open a small unity webgl game on mobile, On android the warning is removed but when the webgl game is opened on our iOS build, the warning reappears as if overriding the conditions given to the compatibilityCheck method. is there a way to fix this? i've tried clearing cache everytime the game opens but everything is still the same..

@JohannesDeml
Copy link
Author

Hi, I'm using an InApp browser plugin to open a small unity webgl game on mobile, On android the warning is removed but when the webgl game is opened on our iOS build, the warning reappears as if overriding the conditions given to the compatibilityCheck method. is there a way to fix this? i've tried clearing cache everytime the game opens but everything is still the same..

Sounds like a caching problem to me. Did you try to empty the safari cache through the settings? What happens if you open the webgl game directly with a browser (maybe in private mode)? And did you try to open another webgl application with your in-app browser (e.g. the linked project https://deml.io/experiments/unity-webgl/2021.1.0f1/). If you are seeing the warning there, then it is a bug, otherwise I'm very sure it has to do with your caching.

@AlghaniAbdullaMsys
Copy link

Hi! thanks for the quick response. as per my immediate superior, the link you gave us worked fine and has no errors or what not. we are still unsure why the error notification still pops up, we clear the browser cache before opening a webgl so that it can have a fresh data on every start up.

if you have any idea how to efficiently and effectively clear cache, please do let me know.

Thanks you for the help!

@JohannesDeml
Copy link
Author

Did you try to empty the safari cache through the settings? What happens if you open the webgl game directly with a browser (maybe in private mode)?

Then the next step is to try the other cases I suggested. If you have the same behavior with safari, I guess your cache clearing does not what you expect it to do. If it does not happen on safari, maybe try to delete and install your app, and maybe a Memory clear or reboot of the device helps as well.

@AlghaniAbdullaMsys
Copy link

AlghaniAbdullaMsys commented Apr 23, 2021

Still no luck in fixing this problem. By the way we are using 2019.4.18f1 and WASM is disabled during build. is this a problem? since i looked up the elements on the test link you sent, it has different files inside the build folder..

Edit: If there's a way to safely disable or remove the compatibilitycheck on the unityloader.JS, please do let me know as i would do that to try to manually remove the warnings

@JohannesDeml
Copy link
Author

@ADCAbdulla I added a troubleshooting section in the readme, maybe that will help you.

@AlghaniAbdullaMsys
Copy link

Hi @JohannesDeml It seems that the problem is within unity 2019. I am using this asset (https://assetstore.unity.com/packages/tools/gui/in-app-web-browser-57532) to open a WebGl unity build and it seems like the error only shows up with unity 2019 webgl builds. I've tested it by opening your example link (https://deml.io/experiments/unity-webgl/2019.3.0f6/) and it did still show the warning modal. Upon testing on 2020 builds, the error disappeared.

If you have fix for this that would be really appreciated. Thanks!

@JohannesDeml
Copy link
Author

@ADCAbdulla Okay, I think I might understand the the problem a bit better. Just to be sure we on the same page: Does your warning read "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway."? (I added this information to the readme to avoid future confusion).
If that is the case, please tell me how I can reproduce the problem with the builds provided in the WebGL-LoadingTest (I added a fresh 2019.4 build, might help). I tried opening the the build with safari, chrom, firefox and through a in app web browser through discord. I only had problems on Firefox with the 2019 build, but with an actuall error (see compatibility note).

@AlghaniAbdullaMsys
Copy link

@JohannesDeml Yes that is the exact error i am seeing when opening the 2019 webgl build on my in-app web browser. To reproduce that error you need to use the in-app browser i linked on my previous comment and try to open a 2019 webgl build on iOS. This only shows up on 2019 web builds, this error is gone on 2020 and up

@JohannesDeml
Copy link
Author

@ADCAbdulla Thanks for clarifying. I don't own the asset you linked to, but I'm quite certain I found the problem: I guess, in your in-app browser the variable UnityLoader.SystemInfo.hasWebGL is false. So what you can do, is remove all compatibility checks, so no warnings can be shown. You can search the unityloader.js for compatibilityCheck:function to find the code you need to remove (everything inside the function). For me, the code to remove looks like this:

UnityLoader.SystemInfo.hasWebGL?UnityLoader.SystemInfo.mobile?e.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.",[{text:"OK",callback:t}]):["Edge","Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?e.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:t}]):t():e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])

this needs to be replaced with t().

Remove the old script of mine, and replace it with this one:

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveWebGLSupportWarning.cs">
//   Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
//   Johannes Deml
//   public@deml.io
// </author>
// --------------------------------------------------------------------------------------------------------------------

#if !UNITY_2020_1_OR_NEWER //Not needed anymore in 2020 and above
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace Supyrb
{
	/// <summary>
	/// removes all warning popups for webgl builds
	/// </summary>
	public class RemoveWebGLSupportWarning
	{
		[PostProcessBuild]
		public static void OnPostProcessBuild(BuildTarget target, string targetPath)
		{
			if (target != BuildTarget.WebGL)
			{
				return;
			}

			var buildFolderPath = Path.Combine(targetPath, "Build");
			var info = new DirectoryInfo(buildFolderPath);
			var files = info.GetFiles("*.js");
			for (int i = 0; i < files.Length; i++)
			{
				var file = files[i];
				var filePath = file.FullName;
				var text = File.ReadAllText(filePath);
				text = text.Replace("UnityLoader.SystemInfo.hasWebGL?UnityLoader.SystemInfo.mobile?e.popup(\"Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.\",[{text:\"OK\",callback:t}]):[\"Edge\",\"Firefox\",\"Chrome\",\"Safari\"].indexOf(UnityLoader.SystemInfo.browser)==-1?e.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:t}]):t():e.popup(\"Your browser does not support WebGL\",[{text:\"OK\",callback:r}])", "t()");

				Debug.Log("Removing all webgl compatibility warnings from " + filePath);
				File.WriteAllText(filePath, text);
			}
		}
	}
}
#endif

You can also replace this function by hand, but that seems rather tedious to do, the script will do it for you :) Make sure the content is the same. I made a build with 2019.4.25f1 for you to test, if this solution works for you (I would be really surprised if the build still shows the message): https://deml.io/experiments/unity-webgl/2019.4.25f1-no-checks/

@AlghaniAbdullaMsys
Copy link

@JohannesDeml the fix work. I'm guessing there's a bypass that we are encountering from using the in app browser. but all in all no warning modals are appearing now. This fix helped us a lot with our projects. Thank you so much for the help and thank you for being responsive!

@dianadorinamita
Copy link

hi, i just tested in unity 2019.4.25 and is stuck on loading, I added default template and is loading so the problem is from custom template, can you help me to fix please?

@JohannesDeml
Copy link
Author

hi, i just tested in unity 2019.4.25 and is stuck on loading, I added default template and is loading so the problem is from custom template, can you help me to fix please?

Hi @dianadorinamita,
So I guess you are talking about the template in the WebGL Loading Test repo?!
If that is the case: That is expected, the template I built there is compatible with Unity 2020.1 and up. There has been a change on ow to write templates with Unity 2020. If you need a similar template for Unity 2019, you can hire me to do so (drop me a line at public@deml.io).

@bowlingforsoap
Copy link

Thanks for the script!
It didn't work out of the box with Unity 2021.2.0f1, but I found that the "builds are not supported on mobile devices" message is coming from the index.html and just commented out the line in OnPostProcessBuild, then the popup is not there anymore.

@JohannesDeml
Copy link
Author

@bowlingforsoap Ah interesting, thanks for the note. I'm using a custom template for quite some while now, so I didn't see the change. With that note unity is a lot less annoying than with the last one (which was a popup, you had to click away).

@PrefixWiz
Copy link

Hi @bowlingforsoap : Could you please explain which OnPostProcessBuild line we need to comment out? Is this in OP's script? Obviously the index.html doesn't have this line in their. Im using 2021.1.15f1. Thanks!

@JohannesDeml
Copy link
Author

@PrefixWiz This is about the unity template, and not about the attached javascript, that is manipulated by this script. You can easily change the template used for the project (this changes the index.html, and probably also some css and javascript stuff). I have a quite minimalistic responsive template. There you won't have any issue with mobile warnings, maybe this is interesting for you :)

@bowlingforsoap
Copy link

@PrefixWiz I'm not sure I understood correctly what you are asking, but actually the javascript for the mobile device check is embedded into the index.html, so that's what the OnPostProcessBuild looks like for me in the end:

	[PostProcessBuild]
	public static void OnPostProcessBuild(BuildTarget target, string targetPath)
	{
		if (target != BuildTarget.WebGL)
		{
			return;
		}

		var info = new DirectoryInfo(targetPath);
		var files = info.GetFiles("index.html");
		for (int i = 0; i < files.Length; i++)
		{
			var file = files[i];
			var filePath = file.FullName;
			var text = File.ReadAllText(filePath);
			text = text.Replace(TEXT_TO_COMMENT_OUT, "//"+TEXT_TO_COMMENT_OUT);

			Debug.Log("Removing mobile warning from " + filePath);
			File.WriteAllText(filePath, text);
		}
	}

where TEXT_TO_COMMENT_OUT = "unityShowBanner('WebGL builds are not supported on mobile devices.');"

@bestcrazygames2019
Copy link

for unity 5.6 will work?

@JohannesDeml
Copy link
Author

for unity 5.6 will work?

Please test it and let us know, I think it should work, but maybe they did rename the method since then.

@T-Rapz
Copy link

T-Rapz commented Sep 29, 2022

So should I create the 'editor' folder myself?

@JohannesDeml
Copy link
Author

So should I create the 'editor' folder myself?

Yes. It needs to be Editor with a capital E. If you don't know about Editor folders, I highly recommend checking them out: https://docs.unity3d.com/Manual/SpecialFolders.html

@pravinm002
Copy link

@JohannesDeml I checkout the "https://github.com/JohannesDeml/UnityWebGL-LoadingTest" and make a build to run that on safari browser but it shows that webgl2 not supported warning, any help?

@JohannesDeml
Copy link
Author

@pravinm002 That sounds like a different warning. Is it on safari iOS? If so on which iOS version are you on? Do you also get it with the demo scenes from the project (e.g. https://deml.io/experiments/unity-webgl/2022.2.18f1-urp-webgl2/)? Can you post a screenshot of the warning?

@pravinm002
Copy link

@JohannesDeml Yes its on ipad, safari browser and its iOS - 14.5.1, and here is the warning, I have build the main scene from loading test project
IMG_DE8A32339A35-1
Screenshot 2023-05-10 at 5 11 14 PM

@JohannesDeml
Copy link
Author

JohannesDeml commented May 10, 2023

@pravinm002 Ah okay, for iOS 14.5 there is no support for WebGL2 by default, support starts at iOS 15.
image

So the warning is probably a warning from the OS itself and not by unity. If you want to target older iOS devices, just target WebGL1 instead. You can test what comination works for you by trying out the builds on your iPad listed here: https://deml.io/experiments/unity-webgl/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment