Hook the WebSocket function on the WebWorker side

Asked 2 years ago, Updated 2 years ago, 147 views

Can I hook the Websocket constructor and onmessage on the WebWorker (Dedicated Worker)?

If it is Main thread, you can hook it with JavaScript Proxy, but I would like to do this to Websocket on the WebWorker side.

The WebWorker's window is a different object from the Main thread, so even if you use Proxy on the Main side, it will not be reflected on the WebWorker side.

What should I do?

javascript web-scraping websocket web-worker

2022-09-30 10:25

1 Answers

You can execute code like globalThis.WebSocket=MyWebSocket; on the target worker.

I think it's impossible if you can't modify the code that works with the worker.


2022-09-30 10:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.