brendan-duncan / webgpu_inspector

Inspection debugger for WebGPU
MIT License
161 stars 4 forks source link

WebWorker auto-inspection breaks https://2024.utsubo.com #12

Closed brendan-duncan closed 4 months ago

brendan-duncan commented 4 months ago

https://2024.utsubo.com

Starting WebGPU Inspector causes the page to have the following errors and not render correctly,

offscreen-CbQ90caE.js:1 Error loading asset: TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Failed to parse URL from /glb/atlas.png
    at lb.load (vendor-HHZJFZia.js:44:61458)
    at offscreen-CbQ90caE.js:1:8283
    at new Promise (<anonymous>)
    at Xe.loadResource (offscreen-CbQ90caE.js:1:7838)
    at offscreen-CbQ90caE.js:1:7742
    at Array.map (<anonymous>)
    at Xe.load (offscreen-CbQ90caE.js:1:7552)
    at is.init (offscreen-CbQ90caE.js:1:24852)
    at new <anonymous> (offscreen-CbQ90caE.js:1:3492)
    at new is (offscreen-CbQ90caE.js:1:24622)
(anonymous) @ offscreen-CbQ90caE.js:1
(anonymous) @ vendor-HHZJFZia.js:44
Promise.catch (async)
load @ vendor-HHZJFZia.js:44
(anonymous) @ offscreen-CbQ90caE.js:1
loadResource @ offscreen-CbQ90caE.js:1
(anonymous) @ offscreen-CbQ90caE.js:1
load @ offscreen-CbQ90caE.js:1
init @ offscreen-CbQ90caE.js:1
(anonymous) @ offscreen-CbQ90caE.js:1
is @ offscreen-CbQ90caE.js:1
os @ offscreen-CbQ90caE.js:1
s @ vendor-HHZJFZia.js:369Understand this error

offscreen-CbQ90caE.js:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'scene')
    at ss.init (offscreen-CbQ90caE.js:1:22085)
    at new <anonymous> (offscreen-CbQ90caE.js:1:3492)
    at new ss (offscreen-CbQ90caE.js:1:16289)
    at is.onLoadEnd (offscreen-CbQ90caE.js:1:26068)
    at Ue.fireMethod (offscreen-CbQ90caE.js:1:1670)
    at offscreen-CbQ90caE.js:1:2980
    at Array.forEach (<anonymous>)
    at Ue.trigger (offscreen-CbQ90caE.js:1:2964)
    at Xe.finish (offscreen-CbQ90caE.js:1:9935)
    at offscreen-CbQ90caE.js:1:7803
brendan-duncan commented 4 months ago

The site is doing a fetch request from a path such as '/glb/atlas.png'. Because the real worker script is being loaded from an import via a generated script, it can't resolve the paths.

brendan-duncan commented 4 months ago

The issue can be reproduced by adding

const response = await fetch('/test/triangle.html');
const text = await response.text();
console.log(text);

to test/webgpu_worker.js

brendan-duncan commented 4 months ago

I made a branch to experiment with solutions, https://github.com/brendan-duncan/webgpu_inspector/tree/web_worker_fetch.

Something that partially worked is I store the host url of the worker script. Then I hijacked "fetch", and if the URL starts with "/", I prepend the host url.

That made the modified test/worker.html test work, and it resolved the first error from that threejs site. It still has the error about the null scene.

brendan-duncan commented 4 months ago

The null scene is because it's from a Request. Guess I'll try hijacking that too.

brendan-duncan commented 4 months ago

Intercepting Request seems to work and things are loading and inspecting on that threejs site now.

Feels a bit awkward and error prone we're intercepting so many things now, but it's pretty cool that it works.

brendan-duncan commented 4 months ago

Merged into main. I'll continue poking at it to see if anything else breaks.

csnewman commented 4 months ago

I suspect we'll have a few of these, off the top of my head, we'll likely need to patch:

While the scope of things that could be patch is probably quite large, I can't imagine games will be using them, so aren't an immediate concern.

brendan-duncan commented 4 months ago

yeah, might just have to patch these on a case by case basis. I did fetch already. I could wrap websocket and url. There could be others that I'm not thinking of. At least a bunch of APIs aren't available to WebWorkers, like DOM objects or WebRTC, so it could be worse.