Skip to content

Commit

Permalink
Improve timing of scriptlet injection (#3286)
Browse files Browse the repository at this point in the history
* 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 ghostery/broken-page-reports#267
  • Loading branch information
chrmod authored Jun 2, 2023
1 parent 608ebbc commit a539957
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/adblocker-webextension-cosmetics/adblocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ function handleResponseFromBackground(

// Inject scripts
if (scripts) {
setTimeout(() => {
for (const script of scripts) {
for (const script of scripts) {
try {
injectScript(script, window.document);
} catch (e) {
// continue regardless of error
}
}, 0);
}
}

// Extended CSS
Expand Down

0 comments on commit a539957

Please sign in to comment.