YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
21 stars 8 forks source link

Full screen toggle in HTML5 triggers cross-origin error #7130

Open gm-bug-reporter[bot] opened 1 month ago

gm-bug-reporter[bot] commented 1 month ago

Description

Hi there!

I recently published an HTML5 version of my game in itch.io and newgrounds. GM's "full-screen with F10" feature works just fine when I run the game locally, but in both itch.io and newgrounds I'm getting this error when I try to switch to full screen:

[CODE] theplanetologist.js?…st=1685922900:17384 Uncaught DOMException: Failed to read a named property 'chrome' from 'Window': Blocked a frame with origin "https://html-classic.itch.zone" from accessing a cross-origin frame. at _U03 (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17384:169) at _413 (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17392:183) at window.onkeydown (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17391:53) _U03 @ theplanetologist.js?…st=1685922900:17384 _413 @ theplanetologist.js?…st=1685922900:17392 window.onkeydown @ theplanetologist.js?…st=1685922900:17391 [/CODE]

I'm no expert in web development, but I think GameMaker's HTML5 full-screen toggle logic is breaching some kind of cross-origin security, at least in Chrome. If I'm correct, then I suppose this can only be fixed by GM.

The offending line of code can be seen below.

[CODE=javascript]

function _U03() { var _282 = document.getElementById("gm4html5_div_id"); if (_282) { _K03 = _282.style.left; _L03 = _282.style.top; _M03 = _282.style.margin; var top = window.parent; if (top != null) { if (top.chrome != null && top.chrome.app != null && top.chrome.app.window != null) { // <- THE EXCEPTION IS THROWN AT THIS LINE var _V03 = top.chrome.app.window.current(); if (_V03 != null) { var _dM1 = window.parent.document.getElementById("container"); var _W03 = window.parent.document.getElementById("game"); if (_dM1 != null) { _N03 = _dM1.style.width; _O03 = _dM1.style.height; _R03 = _dM1.style.left; _P03 = _dM1.style.margin; _Q03 = _dM1.style.position; } [/CODE]

Thanks in advance!

Steps To Reproduce

NOTE: This error doesn't appear when running the HTML project locally with GM but only once it is embedded into a site.

It is possible catch the exception when it's thrown by clicking the "break on uncatched exceptions" in the inspector.

Which version of GameMaker are you reporting this issue for?

IDE v2024.6.2.162 Runtime v2024.6.1.208

Which operating system(s) are you seeing the problem on?

Windows 10.0.19045.0

Which platform(s) are you seeing the problem on?

HTML5

09484999-a942-46d1-ba5c-54f507ce4401

guillermoares commented 1 month ago

Hi! I'm the reporter :)

I see some things didn't print out as I expected in the ticket. Rewriting this here for clarity.

I recently published an HTML5 version of my game in itch.io and newgrounds. GM's "full-screen with F10" feature works just fine when I run the game locally, but in both itch.io and newgrounds I'm getting this error when I try to switch to full screen:

theplanetologist.js?…st=1685922900:17384 Uncaught DOMException: Failed to read a named property 'chrome' from 'Window': Blocked a frame with origin "https://html-classic.itch.zone" from accessing a cross-origin frame.
    at _U03 (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17384:169)
    at _413 (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17392:183)
    at window.onkeydown (https://html-classic.itch.zone/html/11088448/html5game/theplanetologist.js?cachebust=1685922900:17391:53)
_U03    @    theplanetologist.js?…st=1685922900:17384
_413    @    theplanetologist.js?…st=1685922900:17392
window.onkeydown    @    theplanetologist.js?…st=1685922900:17391

I'm no expert in web development, but I think GameMaker's HTML5 full-screen toggle logic is breaching some kind of cross-origin security, at least in Chrome. If I'm correct, then I suppose this can only be fixed by GM.

The offending line of code can be seen below.

function _U03() {
    var _282 = document.getElementById("gm4html5_div_id");
    if (_282) {
        _K03 = _282.style.left;
        _L03 = _282.style.top;
        _M03 = _282.style.margin;
        var top = window.parent;
        if (top != null) {
            if (top.chrome != null && top.chrome.app != null && top.chrome.app.window != null) {  // <- THE EXCEPTION IS THROWN AT THIS LINE
                var _V03 = top.chrome.app.window.current();
                if (_V03 != null) {
                    var _dM1 = window.parent.document.getElementById("container");
                    var _W03 = window.parent.document.getElementById("game");
                    if (_dM1 != null) {
                        _N03 = _dM1.style.width;
                        _O03 = _dM1.style.height;
                        _R03 = _dM1.style.left;
                        _P03 = _dM1.style.margin;
                        _Q03 = _dM1.style.position;
                    }

To reproduce:

  1. Start the game in itch.io (The Planetologist @itch.io).
  2. Open the inspector (I'm using Chrome).
  3. Press F10 to switch to full-screen.
  4. The error will appear in the console log. It is also posible to use the "break on uncatched exceptions" box in the inspector to catch the code line in which the error happens.

What do you think? Let me know if I can provide any other useful info :)

Thanks in advance!

guillermoares commented 1 month ago

I see this has been moved to the backlog. Was this confirmed as a bug? Could you provide some kind of workaround until this gets fixed? I suppose I could manually edit the JS code after compiling to tweak this, but I'm not sure what the tweak should be exactly. Any guidance will be welcome 😃

guillermoares commented 4 weeks ago

In case someone else is having this issue, replacing

top.chrome != null && top.chrome.app != null && top.chrome.app.window != null

with false in the JS file "solves" the issue in both Newgrounds and Itch.io. Not a real solution though.