kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game, fun
https://kaplayjs.com
MIT License
536 stars 35 forks source link

bug: conflicts between `navigation()` and Safari's `navigation()` #289

Closed dragoncoder047 closed 1 month ago

dragoncoder047 commented 3 months ago

Describe the bug

This bug does not occur in Chrome or Firefox, it only occurs in Safari. The game just fails to load.

Version

3001.0.0-alpha.19 loaded from unpkg.

To Reproduce

Call kaplay(). That's it!!

Expected behavior

The game works!

Screenshots

Screenshot 2024-07-28 at 1 58 19 PM
lajbel commented 3 months ago

will investigate, I don't have Safari lol, that's the only problem

lajbel commented 3 months ago

can you disable globals and test if it works?

lajbel commented 3 months ago

Is global: false in kaplay({})

niceEli commented 3 months ago

Testing KAPLAY alpha 18.1 on iOS/iPadOS Safari I don't have this issue

niceEli commented 3 months ago

After further testing on alpha 19.1 there also seems to be no issues. What version of kaplay are you using?

dragoncoder047 commented 3 months ago

Im using whatever loads from https://unpkg.com/kaplay@3001.0.0-alpha.19.1/dist/kaplay.js -- 3001alpha19.1, I guess. And I am on Mac Safari, not iPad.

dragoncoder047 commented 3 months ago

Is global: false in kaplay({})

never mind, this fixes the "read only property" error.

But shouldn't this be documented somewhere ("known bug: you can't use global: true in Safari")?

lajbel commented 3 months ago

It was to confirm what is related to the error, will investigate more

lajbel commented 3 months ago

It still happens?

dragoncoder047 commented 3 months ago

It still happens?

hang on, will test

dragoncoder047 commented 3 months ago

It still happens?

hang on, will test

yes

and this is with bleeding edge from #301

lajbel commented 2 months ago

I don't have a safari device (only iPhone, and there works) so it's kinda hard to test but the bug seems to be here:

kaplay.ts 1326

    if (gopt.global !== false) {
        for (const key in k) {
            (<any> window[<any> key]) = k[key as keyof KAPLAYCtx];
        }
    }
lajbel commented 2 months ago

Maybe window is readonly in Safari? or we are assigning a readonly prop that's present only on Safari?

dragoncoder047 commented 2 months ago

I figured out what is the problem: navigation() conflicts with the Navigation API that can be enabled in Safari with a feature flag (I have it turned on and it must be readonly).

I found it by adding:

    if (gopt.global !== false) {
        for (const key in k) {
+           console.log("adding key:", key);
            (<any> window[<any> key]) = k[key as keyof KAPLAYCtx];
        }
    }

and I got

Screenshot 2024-09-07 at 3 01 02 PM

Stinks that the WebKit people couldn't get the error message to say which property was readonly, that would have made it so much more obvious from the beginning...

lajbel commented 2 months ago

we probably should change it

dragoncoder047 commented 2 months ago

My suggestion would be "navigator" because that's what the component makes the object into, and the docs for it use that language too

dragoncoder047 commented 2 months ago

gosh, whoops, never mind, that one conflicts with an even importanter property!!

mflerackers commented 2 months ago

Yes, navigator was my first choice, but I couldn't use it due to that reason. That's why I took navigation. We had the same problem with anchor, which was called origin originally.