From 81bd93a72d0b49fd78908f7c467ae9f324791e23 Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 2 Jul 2018 01:50:32 +0200 Subject: Simplified and apparently more reliable+flexible+efficient dynamic script injection method. --- src/content/media.js | 27 ++++++++++++++++----------- src/content/webglHook.js | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src/content') diff --git a/src/content/media.js b/src/content/media.js index 22bf014..4ca8942 100644 --- a/src/content/media.js +++ b/src/content/media.js @@ -1,4 +1,4 @@ -console.log("Media Hook", document.documentElement.innerHTML); +debug("Media Hook (blocked %s)", !!window.mediaBlocker, document.URL, document.documentElement && document.documentElement.innerHTML); try { (() => { let unpatched = new Map(); @@ -25,9 +25,6 @@ try { patch(window.MediaSource.prototype, "addSourceBuffer", function(mime, ...args) { let ms = this; let urls = urlMap.get(ms); - let me = Array.from(document.querySelectorAll("video,audio")) - .find(e => e.srcObject === ms || urls && urls.has(e.src)); - let exposedMime = `${mime} (MSE)`; let request = { id: "noscript-media", @@ -40,13 +37,21 @@ try { notifyPage(); if (window.mediaBlocker) { - try { - let ph = PlaceHolder.create("media", request); - ph.replace(me); - PlaceHolder.listen(); - } catch (e) { - error(e); - } + (async () => { + let me = Array.from(document.querySelectorAll("video,audio")) + .find(e => e.srcObject === ms || urls && urls.has(e.src)); + + if (!me) return; + let exposedMime = `${mime} (MSE)`; + + try { + let ph = PlaceHolder.create("media", request); + ph.replace(me); + PlaceHolder.listen(); + } catch (e) { + error(e); + } + })(); throw new Error(`${exposedMime} blocked by NoScript`); } diff --git a/src/content/webglHook.js b/src/content/webglHook.js index ba0d769..5b83025 100644 --- a/src/content/webglHook.js +++ b/src/content/webglHook.js @@ -1,4 +1,4 @@ -console.log("WebGL Hook", document.documentElement.innerHTML); +console.log("WebGL Hook", document.URL, document.documentElement && document.documentElement.innerHTML); try { let proto = HTMLCanvasElement.prototype; let getContext = proto.getContext; -- cgit v1.2.3