mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-12 18:04:16 +01:00
Throttle down repeated scriptlet logging information
Related feedback https://github.com/uBlockOrigin/uBlock-issues/issues/3378#issuecomment-2356422784
This commit is contained in:
parent
acffae6a21
commit
e8f6f3ddff
1 changed files with 9 additions and 0 deletions
|
@ -176,9 +176,18 @@ function safeSelf() {
|
||||||
const bc = new self.BroadcastChannel(scriptletGlobals.bcSecret);
|
const bc = new self.BroadcastChannel(scriptletGlobals.bcSecret);
|
||||||
let bcBuffer = [];
|
let bcBuffer = [];
|
||||||
safe.logLevel = scriptletGlobals.logLevel || 1;
|
safe.logLevel = scriptletGlobals.logLevel || 1;
|
||||||
|
let lastLogType = '';
|
||||||
|
let lastLogText = '';
|
||||||
|
let lastLogTime = 0;
|
||||||
safe.sendToLogger = (type, ...args) => {
|
safe.sendToLogger = (type, ...args) => {
|
||||||
if ( args.length === 0 ) { return; }
|
if ( args.length === 0 ) { return; }
|
||||||
const text = `[${document.location.hostname || document.location.href}]${args.join(' ')}`;
|
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 ) {
|
if ( bcBuffer === undefined ) {
|
||||||
return bc.postMessage({ what: 'messageToLogger', type, text });
|
return bc.postMessage({ what: 'messageToLogger', type, text });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue