summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2019-11-16 19:05:02 +0100
committerhackademix2019-11-16 19:05:13 +0100
commit1fc69298f59426cf4cd8bb0f413c66af6a68faab (patch)
tree057e104135d25ffe9502917e8a2947d7b15564d5
parenta1afd19a0e79ac9c77784e50f2eb96a9dbe8da4e (diff)
downloadnoscript-1fc69298f59426cf4cd8bb0f413c66af6a68faab.tar.gz
noscript-1fc69298f59426cf4cd8bb0f413c66af6a68faab.tar.xz
noscript-1fc69298f59426cf4cd8bb0f413c66af6a68faab.zip
[Chromium] Prevent duplicated MSE placeholders (e.g. on Youtube).
-rw-r--r--src/content/media.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/content/media.js b/src/content/media.js
index ae438f9..5c258f2 100644
--- a/src/content/media.js
+++ b/src/content/media.js
@@ -67,16 +67,24 @@ if ("MediaSource" in window) {
} else if ("SecurityPolicyViolationEvent" in window) {
// Chromium
+ let createPlaceholders = () => {
+ let request = notify(false);
+ for (let me of document.querySelectorAll("video,audio")) {
+ if (!(me.src || me.currentSrc) || me.src.startsWith("blob")) {
+ createPlaceholder(me, request);
+ }
+ }
+ }
+ let processedURIs = new Set();
+ let whenReady = false;
addEventListener("securitypolicyviolation", e => {
if (!e.isTrusted || ns.allows("media")) return;
let {blockedURI, violatedDirective} = e;
- if (blockedURI.startsWith("blob") && violatedDirective.startsWith("media-src")) {
- let request = notify(false);
- for (let me of document.querySelectorAll("video,audio")) {
- if (!(me.src || me.currentSrc) || me.src.startsWith("blob")) {
- createPlaceholder(me, request);
- }
- }
+ if (blockedURI.startsWith("blob") &&
+ violatedDirective.startsWith("media-src") &&
+ !processedURIs.has(blockedURI)) {
+ processedURIs.add(blockedURI);
+ setTimeout(createPlaceholders, 0);
}
}, true);
}