Fallback to requestAnimationFrame when requestIdleCallback is not available

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3237
This commit is contained in:
Raymond Hill 2024-05-16 09:28:09 -04:00
parent 7f0b2f4a5e
commit 59ffc96e89
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 9 additions and 3 deletions

View File

@ -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();
});