gorhill / uBO-Extra

A companion extension to uBlock Origin
GNU General Public License v3.0
654 stars 42 forks source link

[suggestion] WebSocket Class Manipulation Won't Work #51

Closed ghost closed 7 years ago

ghost commented 7 years ago

When trying to override the WebSocket class, at least in Chrome versions 58+, you'll see that the extension won't actually do anything, meaning the code is there, context-scripts will run as usual, but WebSocket class will still won't be modified.

This is apparently a new security measure to prevent extensions from dealing with the JavaScript classes regarding socket connections, not 100% sure why.

I saw you (kind of) workaround this issue by providing a nice wrapper to WebSocket with extra functionality (which is cool!)

If you are getting an inconsistent results with the extension (it will probably only happen on newer Chrome versions), I've found that making the extension write a script into the DOM, that will be executed from the SCOPE of the the page, instead of directly modifying WebSocket class, will solve it.

I simply base64'ed the code and injected it into the page's bottom, you can see an example on how it works in this one.

gorhill commented 7 years ago

When trying to override the WebSocket class, at least in Chrome versions 58+, you'll see that the extension won't actually do anything, meaning the code is there, context-scripts will run as usual, but WebSocket class will still won't be modified.

The WebSocket wrapper code is skipped for Chromium 58+, because websocket connection attempts are properly reported to webRequest API for version 58+.