Skip to content

Commit

Permalink
Fallback to requestAnimationFrame when requestIdleCallback is not ava…
Browse files Browse the repository at this point in the history
…ilable

Related issue:
uBlockOrigin/uBlock-issues#3237
  • Loading branch information
gorhill committed May 16, 2024
1 parent 7f0b2f4 commit 59ffc96
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ function safeSelf() {
}, []);
return this.Object_fromEntries(entries);
},
onIdle(fn, options) {
if ( self.requestIdleCallback ) {
return self.requestIdleCallback(fn, options);
}
return self.requestAnimationFrame(fn);
},
};
scriptletGlobals.safeSelf = safe;
if ( scriptletGlobals.bcSecret === undefined ) { return safe; }
Expand Down Expand Up @@ -2232,7 +2238,7 @@ function removeAttr(
}
}
if ( skip ) { return; }
timer = self.requestIdleCallback(rmattr, { timeout: 67 });
timer = safe.onIdle(rmattr, { timeout: 67 });
};
const start = ( ) => {
rmattr();
Expand Down Expand Up @@ -2310,7 +2316,7 @@ function removeClass(
}
}
if ( skip ) { return; }
timer = self.requestIdleCallback(rmclass, { timeout: 67 });
timer = safe.onIdle(rmclass, { timeout: 67 });
};
const observer = new MutationObserver(mutationHandler);
const start = ( ) => {
Expand Down Expand Up @@ -3523,7 +3529,7 @@ function hrefSanitizer(
if ( shouldSanitize ) { break; }
}
if ( shouldSanitize === false ) { return; }
timer = self.requestIdleCallback(( ) => {
timer = safe.onIdle(( ) => {
timer = undefined;
sanitize();
});
Expand Down

0 comments on commit 59ffc96

Please sign in to comment.