1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-08 20:54:49 +01:00

document.write and document.writeln protection broke pages

Fixes #365
This commit is contained in:
kkapsner 2019-06-11 23:09:13 +02:00
parent 27ddc8a683
commit 1737344480
3 changed files with 34 additions and 25 deletions

View File

@ -159,8 +159,9 @@
"write" "write"
); );
const documentWrite = documentWriteDescriptor.value; const documentWrite = documentWriteDescriptor.value;
documentWriteDescriptor.value = exportFunction(function write(str){ documentWriteDescriptor.value = exportFunction(function write(markup){
str = "" + str; for (let i = 0, l = arguments.length; i < l; i += 1){
const str = "" + arguments[i];
// weird problem with waterfox and google docs // weird problem with waterfox and google docs
const parts = ( const parts = (
str.match(/^\s*<!doctype/i) && str.match(/^\s*<!doctype/i) &&
@ -175,6 +176,7 @@
observe(); observe();
} }
} }
}
}, window); }, window);
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor); Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor);
@ -186,10 +188,11 @@
"writeln" "writeln"
); );
const documentWriteln = documentWritelnDescriptor.value; const documentWriteln = documentWritelnDescriptor.value;
documentWritelnDescriptor.value = exportFunction(function writeln(str){ documentWritelnDescriptor.value = exportFunction(function writeln(markup){
str = "" + str; for (let i = 0, l = arguments.length; i < l; i += 1){
const str = "" + arguments[i];
const parts = str.split(/(?=<)/); const parts = str.split(/(?=<)/);
const length = parts.length - 1; const length = parts.length;
const scripts = window.document.getElementsByTagName("script"); const scripts = window.document.getElementsByTagName("script");
for (let i = 0; i < length; i += 1){ for (let i = 0; i < length; i += 1){
documentWrite.call(this, parts[i]); documentWrite.call(this, parts[i]);
@ -198,7 +201,8 @@
observe(); observe();
} }
} }
documentWriteln.call(this, parts[length]); }
documentWriteln.call(this, "");
}, window); }, window);
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor); Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor);
}; };

View File

@ -8,6 +8,7 @@ Version 0.5.11:
fixes: fixes:
- improved protection of (i)frame properties - improved protection of (i)frame properties
- document.write and document.writeln protection broke pages
known issues: known issues:
- if a data URL is blocked the page action button does not appear - if a data URL is blocked the page action button does not appear

View File

@ -13,6 +13,10 @@
{ {
"version": "0.5.11Alpha20190611", "version": "0.5.11Alpha20190611",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.11Alpha20190611-an+fx.xpi" "update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.11Alpha20190611-an+fx.xpi"
},
{
"version": "0.5.11Alpha20190612",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.11Alpha20190612-an+fx.xpi"
} }
] ]
} }