microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
481 stars 209 forks source link

arcade kiosk raises error window (Type Error: Failed to fetch) #6013

Closed tballmsft closed 1 year ago

tballmsft commented 1 year ago
  1. open private mode window in (edge) browser
  2. navigate to https://arcade.makecode.com/kiosk
  3. see the following problem ("Type Error: Failed to fetch"):

image

  1. reload and the error goes away
kiki-lee commented 1 year ago

This happened to me yesterday. A refresh fixed it, but I'm not sure what happened.

eanders-ms commented 1 year ago

This is likely fixed in the new deployment. Will test once it makes it out to prod.

Side issue: we need to remove use of window.alert here.

srietkerk commented 1 year ago

When the kiosk is getting the pre-populated games for the kiosk, there is a fetch request and this is likely where we're getting the error. It's hard for me to fully understand why, so I'll stay on the look out for this issue and look into the logs. It's happened to me before, too, but I didn't think to look at the logs then and I haven't been able to repro it, unfortunately.

srietkerk commented 1 year ago

I was able to get a repro and the errors!

image
eanders-ms commented 1 year ago

Looks like there's an open issue for browsers to safelist this header in the context of CORS: https://github.com/whatwg/fetch/issues/911

eanders-ms commented 1 year ago

Retry logic might be the best solution here. Seems like the browser doesn't always send this header, since it works on page refresh. :shrug:

srietkerk commented 1 year ago

I know that page refresh will get the kiosk back in a working state, but this makes me think there's a better way we can approach this. Other arcade applications don't have a problem with fetching assets, so if we can consolidate without retries, I think that would be my preferred path forward.

I guess I'm just curious why this is a problem for kiosk. If, with fully moving this over now, we can more mirror what happens with our other web apps, that would be nicer at least.

eanders-ms commented 1 year ago

Agreed. It would be good to know why this is happening in kiosk and not to similar apps like skillmap and multiplayer. There is something peculiar going on here we're not seeing elsewhere.

eanders-ms commented 1 year ago

The CORS check itself seems entirely unnecessary in this case. It's hitting CDN, all requests to it are cross origin.

srietkerk commented 1 year ago

I now cannot get this to repro very easily. I've restarted my computer many times to try to get the error but I only got it once this morning. The failure I got was not the same, either. I got a network error instead of the CORS error. Not sure how to proceed here.

srietkerk commented 1 year ago

From what I've gathered and chatted with Eric about, including traceparent and tracestate to our allowed headers will be the best route forward for the CORS error that I saw, but if the CORS error isn't the real error to look out for, then I wouldn't want to make that change.

eanders-ms commented 1 year ago

Actually this request isn't hitting our backend so modifying CORS handling isn't an option here.

I can get a 90% repro in Firefox if I hit refresh a bunch. Here's what I see in the sent headers: image

I highlighted the problematic headers. It doesn't always send them. Here's the error response:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://pxt.azureedge.net/blob/9e5e9051f8f72796b42a1e3320fad605192cdbd1//kiosk-data/GameList.json. (Reason: header ‘request-id’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

Retry logic is probably the way to go here.

srietkerk commented 1 year ago

Oh, I'm glad(ish) to see that you got a network error as well. Okay, I'll go with retry logic.

eanders-ms commented 1 year ago

Still seeing this occasionally. Just a thought: I wonder if a small delay before the second fetch attempt would help.

srietkerk commented 1 year ago

Yeah, I can do that. When you see this, are you still getting the same errors?

kiki-lee commented 1 year ago

I can replicate consistently on Safari by holding shift+reload

Screenshot by Dropbox Capture

srietkerk commented 1 year ago

If you reload again will you get the error? I'm worried that just trying to delay the retry a bit won't really solve the problem.

kiki-lee commented 1 year ago

Still happening in my logged-in window. Not happening at all in a private window.

eanders-ms commented 1 year ago

I believe this is fixed now. Please reopen if you see it.

eanders-ms commented 1 year ago

still happening :/

eanders-ms commented 1 year ago

Should be fixed now. Please reopen if you see it again.