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
@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