Throttle down repeated scriptlet logging information

Related feedback
https://github.com/uBlockOrigin/uBlock-issues/issues/3378#issuecomment-2356422784
This commit is contained in:
Raymond Hill 2024-09-17 17:33:06 -04:00
parent acffae6a21
commit e8f6f3ddff
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 9 additions and 0 deletions

View File

@ -176,9 +176,18 @@ function safeSelf() {
const bc = new self.BroadcastChannel(scriptletGlobals.bcSecret);
let bcBuffer = [];
safe.logLevel = scriptletGlobals.logLevel || 1;
let lastLogType = '';
let lastLogText = '';
let lastLogTime = 0;
safe.sendToLogger = (type, ...args) => {
if ( args.length === 0 ) { return; }
const text = `[${document.location.hostname || document.location.href}]${args.join(' ')}`;
if ( text === lastLogText && type === lastLogType ) {
if ( (Date.now() - lastLogTime) < 300000 ) { return; }
}
lastLogType = type;
lastLogText = text;
lastLogTime = Date.now();
if ( bcBuffer === undefined ) {
return bc.postMessage({ what: 'messageToLogger', type, text });
}