webgpu_inspector icon indicating copy to clipboard operation
webgpu_inspector copied to clipboard

Some workers are created with the wrong urls

Open jespertheend opened this issue 1 year ago • 5 comments
trafficstars

One of my applications creates a worker using something like this:

const workerUrl = new URL("./assets/worker/main.js", import.meta.url);
const worker = new Worker(workerUrl.href, { type: "module" });

Normally this works fine and the url resolves to http://localhost:8080/client/src/assets/worker/main.js. But once I start inspecting, workerUrl.href is turned into blob://http://localhost:8080/./assets/worker/main.js and the creation of the worker fails.

This particular worker doesn't touch WebGPU so I wouldn't mind if this particular worker wasn't intercepted.

jespertheend avatar Jul 12 '24 15:07 jespertheend

Yeah, sorry, in order to inspect workers that do use WebGPU it has to intercept all workers. Normally it does this without issue, but the interception process interferes with paths. The compensate for that it tries to fix up paths. Obviously it's failing in this case. I'll investigate as soon as I get a chance.

brendan-duncan avatar Jul 12 '24 15:07 brendan-duncan

I finally have a chance to look into this.

Can you let me know how you have your files laid out, or even a repo? I'm trying to make a repo myself but not having much success.

Also, are you using the Trusted Types API (https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API)?

brendan-duncan avatar Jul 15 '24 02:07 brendan-duncan

Thanks for looking into this!

I'm not using the Trusted Types API. I don't have a public repo unfortunately. The bug seems to be reproducible on https://pelicanparty.games/ferry but it's all heavily minified so I'll try to get a reduced test case going.

jespertheend avatar Jul 15 '24 10:07 jespertheend

Ok well this makes a lot of sense now. I'm using a polyfill to make new Worker('..', {type:'module'}) work. When I remove it, it fixes this particular error.

I made a reduced test case on https://webgpu-inspector-with-module-worker-polyfill.glitch.me in case you want to fix it. But I reckon this is pretty uncommon and in my case I can easily work around the issue by disabling the polyfill. Which I probably should do anyway since it's now supported in all browsers.

I am running into another issue though, but I'll create a new ticket for that. Feel free to close this if you like.

jespertheend avatar Jul 15 '24 10:07 jespertheend

Thanks for the extra info and the repo! I'll definitely be looking into it. I was sure there would be cases where the hacky module interception and path fixing would break, and it's good to find an example.

I'll look at the fetch issue too, which is really the same issue but another good example of it. Might take a couple days, trying to catch up with work after some vacation.

brendan-duncan avatar Jul 15 '24 16:07 brendan-duncan