From 63fe18a7613d561088287ae61c1b00ca83d885ca Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 11 Jan 2024 13:25:19 -0500 Subject: [PATCH] Do not exceed rate-limited calls to handlerBehaviorChanged() Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3063 To prevent spurious performance warnings by chromium-based browsers. --- src/js/broadcast.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/js/broadcast.js b/src/js/broadcast.js index 0bef46c0e..d4293ceb3 100644 --- a/src/js/broadcast.js +++ b/src/js/broadcast.js @@ -69,7 +69,19 @@ export function filteringBehaviorChanged(details = {}) { } filteringBehaviorChanged.throttle = vAPI.defer.create(( ) => { + const { history, max } = filteringBehaviorChanged; + const now = (Date.now() / 1000) | 0; + if ( history.length >= max ) { + if ( (now - history[0]) <= (10 * 60) ) { return; } + history.shift(); + } + history.push(now); vAPI.net.handlerBehaviorChanged(); }); +filteringBehaviorChanged.history = []; +filteringBehaviorChanged.max = Math.min( + browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES - 1, + 19 +); /******************************************************************************/