summaryrefslogtreecommitdiff
path: root/src/content/media.js
diff options
context:
space:
mode:
authorhackademix2018-07-02 01:50:32 +0200
committerhackademix2018-07-02 01:50:32 +0200
commit81bd93a72d0b49fd78908f7c467ae9f324791e23 (patch)
treedaacfeb158f1f6512532d7e4ccafc6da68494aa4 /src/content/media.js
parent673c881559e4f9274be5b54ca35552e12cd8cd76 (diff)
downloadnoscript-81bd93a72d0b49fd78908f7c467ae9f324791e23.tar.gz
noscript-81bd93a72d0b49fd78908f7c467ae9f324791e23.tar.xz
noscript-81bd93a72d0b49fd78908f7c467ae9f324791e23.zip
Simplified and apparently more reliable+flexible+efficient dynamic script injection method.
Diffstat (limited to 'src/content/media.js')
-rw-r--r--src/content/media.js27
1 files changed, 16 insertions, 11 deletions
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`);
}