Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug WebGL build not opening urls on IOS 16.0.2 and Safari 16.1

Discussion in 'Editor & General Support' started by AdrianoVerissimo, Oct 31, 2022.

  1. AdrianoVerissimo

    AdrianoVerissimo

    Joined:
    Jun 17, 2017
    Posts:
    3
    Hello community! It's my first time here in the forum, sorry if I'm not posting the question in the right category.

    I'm going trough a problem running an Unity WebGL build on an iPhone with Safari 16.1 browser and IOS 16.0.2.

    I need to create an Augmented Reality app in Unity that will run in WebGL. This app will have a button, and when it's clicked a new URL will be opened in the browser.

    However, the URL doesn't open when running the app in an iPhone with Safari 16.1 browser and IOS 16.0.2.

    My client has tested using Google Chrome in a iPhone with IOS 16.0.2 and it worked.
    He also tested in an iPhone with IOS version previous to 16.0.2 and it worked.
    So I think that it would be related to the Safari 16.1 browser.

    I've tried at first using Application.OpenURL() but it didn't work.
    I also tried JavaScript code creating plugins with ".jslib" extension files, and it didn't work too.

    Would it be a bug because of the version of Safari? Is there any solution that I can do to solve this problem?
    I don't have an iPhone with IOS 16.0.2 and Safari 16.1 browser, so it's been hard to figure out the problem.

    Here is the .jslib codes that I'm using:
    Code (JavaScript):
    1. // Creating functions for the Unity
    2. mergeInto(LibraryManager.library, {
    3.    // Function with the text param
    4.    OpenURL_CreateNode: function (url, target) {
    5.       // Convert bytes to the text
    6.       var convertedURL = Pointer_stringify(url);
    7.       var convertedTarget = Pointer_stringify(target);
    8.      
    9.       var link = document.createElement("a");
    10.       link.href = convertedURL;
    11.       link.target = target;
    12.  
    13.       link.click();
    14.       link.remove();
    15.    },
    16.  
    17.    OpenURL_WindowOpen: function(url)
    18.    {
    19.       var convertedURL = Pointer_stringify(url);
    20.       window.open(convertedURL);
    21.    }
    22. });
    Here is the C# codes that are calling the .jslib functions:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Runtime.InteropServices;
    5.  
    6.  
    7. public class ButtonController : MonoBehaviour
    8. {
    9.     public string url;
    10.  
    11.     [DllImport("__Internal")]
    12.     public static extern void OpenURL_CreateNode(string url, string target);
    13.  
    14.     [DllImport("__Internal")]
    15.     public static extern void OpenURL_WindowOpen(string url);
    16.  
    17.     public void OpenURL_CreateNode_blank() => OpenURL_CreateNode(url, "_blank");
    18.     public void OpenURL_CreateNode_parent() => OpenURL_CreateNode(url, "_parent");
    19.     public void OpenURL_CreateNode_top() => OpenURL_CreateNode(url, "_top");
    20.  
    21.     public void OpenURL_WindowOpen_Unity()
    22.     {
    23.         OpenURL_WindowOpen(url);
    24.     }
    25. }
    If you want to take a look at the entire project, I've uploaded it on GitHub. It's just a simple screen with some buttons. It's on Unity 2020.3.33f1:
    https://github.com/AdrianoVerissimo/TestButtonIOS_UnityWebGL

    Thank you very much in advance.
     
  2. AdrianoVerissimo

    AdrianoVerissimo

    Joined:
    Jun 17, 2017
    Posts:
    3
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
  4. AdrianoVerissimo

    AdrianoVerissimo

    Joined:
    Jun 17, 2017
    Posts:
    3
    Thank you very much for the reply @Kurt-Dekker !!
    I'll try it and will post the results here after testing.