| Index: lib/requestBlocker.js |
| =================================================================== |
| --- a/lib/requestBlocker.js |
| +++ b/lib/requestBlocker.js |
| @@ -256,6 +256,24 @@ |
| }); |
| let ignoreFilterNotifications = false; |
| +let handlerBehaviorChangedQuota = |
| + browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; |
| + |
| +function propagateHandlerBehaviorChange() |
| +{ |
| + // Make sure to not call handlerBehaviorChanged() more often than allowed |
| + // by browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES. |
| + // Otherwise Chrome notifies the user that this extension is causing issues. |
| + if (handlerBehaviorChangedQuota > 0) |
| + { |
| + browser.webNavigation.onBeforeNavigate.removeListener( |
| + propagateHandlerBehaviorChange |
| + ); |
| + browser.webRequest.handlerBehaviorChanged(); |
| + handlerBehaviorChangedQuota--; |
| + setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); |
| + } |
| +} |
| function onFilterChange(arg, isDisabledAction) |
| { |
| @@ -282,8 +300,16 @@ |
| ignoreFilterNotifications = true; |
| setTimeout(() => |
| { |
| + // Defer handlerBehaviorChanged() until navigation occurs. |
| + // There wouldn't be any visible effect when calling it earlier, |
| + // but it's an expensive operation and that way we avoid to call |
| + // it multiple times, if multiple filters are added/removed. |
| + if (!browser.webNavigation.onBeforeNavigate |
| + .hasListener(propagateHandlerBehaviorChange)) |
| + browser.webNavigation.onBeforeNavigate |
| + .addListener(propagateHandlerBehaviorChange); |
| + |
| ignoreFilterNotifications = false; |
| - ext.webRequest.handlerBehaviorChanged(); |
| FilterNotifier.emit("filter.behaviorChanged"); |
| }); |
| } |