From 8e175ceec7fa03ddfb70d9cce9ab56179994591c Mon Sep 17 00:00:00 2001 From: Krzysztof Modras Date: Fri, 2 Jun 2023 10:04:36 +0200 Subject: [PATCH 1/2] Improve timing of scriptlet injection Some scriptlets like `set-constant` or `json-prune` benefit from being injected ASAP. One very concrete example is YouTube adblocking which fails with any additional delays are introduced. fix https://github.com/ghostery/broken-page-reports/issues/267 --- packages/adblocker-webextension-cosmetics/adblocker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/adblocker-webextension-cosmetics/adblocker.ts b/packages/adblocker-webextension-cosmetics/adblocker.ts index abfde217b1..6a45092683 100644 --- a/packages/adblocker-webextension-cosmetics/adblocker.ts +++ b/packages/adblocker-webextension-cosmetics/adblocker.ts @@ -219,11 +219,13 @@ function handleResponseFromBackground( // Inject scripts if (scripts) { - setTimeout(() => { + try { for (const script of scripts) { injectScript(script, window.document); } - }, 0); + } catch (e) { + // continue regardless of error + } } // Extended CSS From f2438adb608c80cf06aab08e6c1f78a6bd7eecf4 Mon Sep 17 00:00:00 2001 From: Krzysztof Modras Date: Fri, 2 Jun 2023 10:29:51 +0200 Subject: [PATCH 2/2] Update adblocker.ts --- packages/adblocker-webextension-cosmetics/adblocker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/adblocker-webextension-cosmetics/adblocker.ts b/packages/adblocker-webextension-cosmetics/adblocker.ts index 6a45092683..a3a88f028c 100644 --- a/packages/adblocker-webextension-cosmetics/adblocker.ts +++ b/packages/adblocker-webextension-cosmetics/adblocker.ts @@ -219,12 +219,12 @@ function handleResponseFromBackground( // Inject scripts if (scripts) { - try { - for (const script of scripts) { + for (const script of scripts) { + try { injectScript(script, window.document); + } catch (e) { + // continue regardless of error } - } catch (e) { - // continue regardless of error } }