From 9b45333e0d27a5d1000c7dd1b73419eebaf3a808 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 30 Dec 2025 15:36:42 -0500 Subject: [PATCH] [mv3] Fix "Proceed" button not working in strict-block page Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/576 --- platform/mv3/extension/js/ruleset-manager.js | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/platform/mv3/extension/js/ruleset-manager.js b/platform/mv3/extension/js/ruleset-manager.js index 3bbdca991..3758d7d25 100644 --- a/platform/mv3/extension/js/ruleset-manager.js +++ b/platform/mv3/extension/js/ruleset-manager.js @@ -48,9 +48,6 @@ const TRUSTED_DIRECTIVE_BASE_RULE_ID = 8000000; const TRUSTED_DIRECTIVE_PRIORITY = USER_RULES_PRIORITY + 1000000; const STRICTBLOCK_PRIORITY = 29; -let dynamicRegexCount = 0; -let sessionRegexCount = 0; - /******************************************************************************/ const isStrictBlockRule = rule => { @@ -128,6 +125,14 @@ pruneInvalidRegexRules.validated = new Map(); /******************************************************************************/ +async function getDynamicRegexRuleCount() { + const rules = await dnr.getDynamicRules(); + const regexRules = rules.filter(a => Boolean(a.condition?.regexFilter)); + return regexRules.length; +} + +/******************************************************************************/ + async function updateRegexRules(currentRules, addRules, removeRuleIds) { // Remove existing regex-related block rules for ( const rule of currentRules ) { @@ -181,19 +186,19 @@ async function updateDynamicRules() { await updateRegexRules(currentRules, addRules, removeRuleIds); if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; } - const dynamicRegexCountBefore = dynamicRegexCount; - dynamicRegexCount = 0; + const dynamicRegexCountBefore = await getDynamicRegexRuleCount(); + let dynamicRegexCountAfter = 0; let ruleId = 1; for ( const rule of addRules ) { - if ( rule?.condition.regexFilter ) { dynamicRegexCount += 1; } + if ( rule?.condition.regexFilter ) { dynamicRegexCountAfter += 1; } rule.id = ruleId++; } - if ( dynamicRegexCount !== 0 ) { - ubolLog(`Using ${dynamicRegexCount}/${dnr.MAX_NUMBER_OF_REGEX_RULES} dynamic regex-based DNR rules`); + if ( dynamicRegexCountAfter !== 0 ) { + ubolLog(`Using ${dynamicRegexCountAfter}/${dnr.MAX_NUMBER_OF_REGEX_RULES} dynamic regex-based DNR rules`); } // If we increase the number of dynamic regex rules, reset session rules to // reduce risk of hitting maximum regex count - if ( dynamicRegexCount > dynamicRegexCountBefore ) { + if ( dynamicRegexCountAfter > dynamicRegexCountBefore ) { await clearSessionRules(); } @@ -341,7 +346,8 @@ async function updateSessionRules() { const currentRules = await dnr.getSessionRules(); await updateStrictBlockRules(currentRules, addRulesUnfiltered, removeRuleIds); if ( addRulesUnfiltered.length === 0 && removeRuleIds.length === 0 ) { return; } - const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.80; + const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.95; + const dynamicRegexCount = await getDynamicRegexRuleCount(); let regexCount = dynamicRegexCount; let ruleId = 1; for ( const rule of addRulesUnfiltered ) { @@ -351,7 +357,7 @@ async function updateSessionRules() { if ( regexCount < maxRegexCount ) { continue; } rule.id = 0; } - sessionRegexCount = regexCount - dynamicRegexCount; + const sessionRegexCount = regexCount - dynamicRegexCount; const addRules = addRulesUnfiltered.filter(a => a.id !== 0); const rejectedRuleCount = addRulesUnfiltered.length - addRules.length; if ( rejectedRuleCount !== 0 ) {