gorhill / uBO-Extra

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

[suggestion] regarding document.write blocking in Chrome #50

Closed ghost closed 7 years ago

ghost commented 7 years ago

fyi Chrome will blocks document.write, 100% of the scripts written with document.write won't be executed (by design). Also, a user can switch extended blocking to all document.write executions, through chrome://flags. This is related to both extensions and web-pages (included native web-pages source and source modified by context-script).

The workaround (which is actually the proper solution as well..) is the only use document.write to write the DOCTYPE, since it won't work otherwise (when put innerHTML)-- and assign the rest of the HTML source into document.documentElement.innerHTML.

If you're getting inconsistent results with your extension, on different browsers, this is why.

Saw your code uses it, and just thought it might help. Solved it for few of my extensions (for example this one which also stops early parsing to make it more efficient..)

gorhill commented 7 years ago

Using innerHTML does not cause the script tags in it to be executed, unlike document.write. It's not an issue in your extension because all script tags have already been executed, and you are not trying to prevent them from executing.