inline-console icon indicating copy to clipboard operation
inline-console copied to clipboard

Does This Work With Web Workers?

Open mshaw-siouxsteel opened this issue 1 year ago • 2 comments

I'm attempting to debug an issue I have on an iPad regarding OPFS Web Workers, but I'm noticing that the Inline Console isn't getting any of the console.log() messages that I'm sending within my Web Worker. I've verified that I am sending and receiving messages to and from the Web Worker via other console.log() messages, and tested with having the first line of the onmessage within my worker be a console.log() as well.

Is there something I can do to enable logging from Web Workers or does this not have that kind of capability yet?

Thanks in advance!

mshaw-siouxsteel avatar Apr 24 '23 18:04 mshaw-siouxsteel

Hi @mshaw-siouxsteel - Sorry for the slow response.

I've never tested this within a web worker. I'm not terribly familiar with web workers, but my suspicion is the modifications we make to the things like window.onerror and window.onmessage in the main browser thread don't get carried over to the web worker threads?

rwblackburn avatar May 22 '23 13:05 rwblackburn

UNTESTED:

I think you would have to import the script with self.importScripts("inline-console.min.js"). Changes to the window global scope don’t affect worker scopes.

Additionally, and more importantly, you can’t update the DOM from a worker, so the script would have to use ‘postMessage’ to communicate with the main thread and update the visual console.

Having investigated this, I don’t believe there’s any way to modify the global scope of a Worker thread, so in its current implementation, it’s not possible to implement this. Perhaps if the inline-console script exported a function to setup (would global trap the defining scope?, is there anyway to do this without eval?), but not right now.

aarondill avatar May 22 '23 21:05 aarondill