Search Unity

Question WebGL in iframe and right click

Discussion in 'Web' started by rachdan, Jan 19, 2023.

  1. rachdan

    rachdan

    Joined:
    Jan 14, 2021
    Posts:
    4
    Hi!

    I´m actually using Unity WebGL in an iframe in my webapplication.

    The reason for the iframe is because unity doesn´t quit correctly (script files still exist on DOM) after the destroy of a component. I cannot quit the component automatically because i do not have the full control over all navigation scenarios. ==> With an iframe i do not have this problem.

    But actually i can not route the right-click event to my WebGL application. In my Unity-Project i want to use the pressed "right-mouse-click". Does anyone knows a solution for this problem?

    Regard
    Daniel
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,937
  3. rachdan

    rachdan

    Joined:
    Jan 14, 2021
    Posts:
    4
    Thank you.
    I came up with this solution. Preventing the right click forwards the right click also to the Unity App. So everything works finde.
    Code (JavaScript):
    1. window.document.getElementById('xxx').addEventListener('contextmenu', function (e) {
    2.       e.preventDefault();
    3.     }, false);
     
  4. Programmer_1V1

    Programmer_1V1

    Joined:
    May 8, 2021
    Posts:
    3
    Hello, let me first say thank you for offering any help; please let me know what additional info would be helpful.
    I see that you are using an iFrame to display a WebGL build and may be able to help.

    I am working on an application that I have built for WebGL. It is a large project (~240MB) and after updating it recently, I can not get it to run in an iFrame. The previous version worked perfectly (2020.x.x LTS's) but after upgrading the project to URP/2021.x.x LTS, I can not play it from an iFrame.

    After uploading the build to WordPress, I can locate and click the index.html file and open up the build successfully with no issues at all. However, if I create a page and use custom HTML to create an iFrame, and set the source as the index.html, I get errors. Please note, that the build opens successfully if I directly clicked and ran the index.html file directly as it cached the files on my browser. But if I clear the cache and navigate to the page with the iFrame, I again see errors. The build just stops loading between 20-60%, and sometimes has an Abort modal pop-up. I have tried different builds as well related to compression (gzip, gzip with decompression fallback, brotli, brotli with DF, not compressed at all, etc).

    In Network, the GET request is returning with a 206, but shows (failed)


    Any help would be VERY much appreciated, thank you.