1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +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,20 +159,22 @@
"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){
// weird problem with waterfox and google docs const str = "" + arguments[i];
const parts = ( // weird problem with waterfox and google docs
str.match(/^\s*<!doctype/i) && const parts = (
!str.match(/frame/i) str.match(/^\s*<!doctype/i) &&
)? [str]: str.split(/(?=<)/); !str.match(/frame/i)
const length = parts.length; )? [str]: str.split(/(?=<)/);
const scripts = window.document.getElementsByTagName("script"); const length = parts.length;
for (let i = 0; i < length; i += 1){ const scripts = window.document.getElementsByTagName("script");
documentWrite.call(this, parts[i]); for (let i = 0; i < length; i += 1){
allCallback(); documentWrite.call(this, parts[i]);
if (scripts.length && scripts[scripts.length - 1].src){ allCallback();
observe(); if (scripts.length && scripts[scripts.length - 1].src){
observe();
}
} }
} }
}, window); }, window);
@ -186,19 +188,21 @@
"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 parts = str.split(/(?=<)/); const str = "" + arguments[i];
const length = parts.length - 1; const parts = str.split(/(?=<)/);
const scripts = window.document.getElementsByTagName("script"); const length = parts.length;
for (let i = 0; i < length; i += 1){ const scripts = window.document.getElementsByTagName("script");
documentWrite.call(this, parts[i]); for (let i = 0; i < length; i += 1){
allCallback(); documentWrite.call(this, parts[i]);
if (scripts.length && scripts[scripts.length - 1].src){ allCallback();
observe(); if (scripts.length && scripts[scripts.length - 1].src){
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"
} }
] ]
} }