1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

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

View File

@ -155,6 +155,12 @@ function safeSelf() {
}, []); }, []);
return this.Object_fromEntries(entries); return this.Object_fromEntries(entries);
}, },
onIdle(fn, options) {
if ( self.requestIdleCallback ) {
return self.requestIdleCallback(fn, options);
}
return self.requestAnimationFrame(fn);
},
}; };
scriptletGlobals.safeSelf = safe; scriptletGlobals.safeSelf = safe;
if ( scriptletGlobals.bcSecret === undefined ) { return safe; } if ( scriptletGlobals.bcSecret === undefined ) { return safe; }
@ -2232,7 +2238,7 @@ function removeAttr(
} }
} }
if ( skip ) { return; } if ( skip ) { return; }
timer = self.requestIdleCallback(rmattr, { timeout: 67 }); timer = safe.onIdle(rmattr, { timeout: 67 });
}; };
const start = ( ) => { const start = ( ) => {
rmattr(); rmattr();
@ -2310,7 +2316,7 @@ function removeClass(
} }
} }
if ( skip ) { return; } if ( skip ) { return; }
timer = self.requestIdleCallback(rmclass, { timeout: 67 }); timer = safe.onIdle(rmclass, { timeout: 67 });
}; };
const observer = new MutationObserver(mutationHandler); const observer = new MutationObserver(mutationHandler);
const start = ( ) => { const start = ( ) => {
@ -3523,7 +3529,7 @@ function hrefSanitizer(
if ( shouldSanitize ) { break; } if ( shouldSanitize ) { break; }
} }
if ( shouldSanitize === false ) { return; } if ( shouldSanitize === false ) { return; }
timer = self.requestIdleCallback(( ) => { timer = safe.onIdle(( ) => {
timer = undefined; timer = undefined;
sanitize(); sanitize();
}); });