Skip to content

Commit

Permalink
Throttle down repeated scriptlet logging information
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 17, 2024
1 parent acffae6 commit e8f6f3d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit e8f6f3d

Please sign in to comment.