From 59ffc96e8970a23ae9a76dd48b807a9ce5017e38 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 16 May 2024 09:28:09 -0400 Subject: [PATCH] Fallback to requestAnimationFrame when requestIdleCallback is not available Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3237 --- assets/resources/scriptlets.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index f1722ee93..051b6e218 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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; } @@ -2232,7 +2238,7 @@ function removeAttr( } } if ( skip ) { return; } - timer = self.requestIdleCallback(rmattr, { timeout: 67 }); + timer = safe.onIdle(rmattr, { timeout: 67 }); }; const start = ( ) => { rmattr(); @@ -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 = ( ) => { @@ -3523,7 +3529,7 @@ function hrefSanitizer( if ( shouldSanitize ) { break; } } if ( shouldSanitize === false ) { return; } - timer = self.requestIdleCallback(( ) => { + timer = safe.onIdle(( ) => { timer = undefined; sanitize(); });