From 66238899208632ce12181a04692a3b29c08e5478 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 29 Sep 2025 13:07:59 -0400 Subject: [PATCH] [mv3] Improve details of troublshooting info Also, avoid loading troubleshooting module in service worker as it's of use only as a user interface component. --- platform/mv3/extension/js/background.js | 16 ++++--- platform/mv3/extension/js/dashboard.js | 9 ++-- platform/mv3/extension/js/report.js | 6 +-- platform/mv3/extension/js/troubleshooting.js | 48 ++++++++++++-------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/platform/mv3/extension/js/background.js b/platform/mv3/extension/js/background.js index ea96b5563..06e30a30f 100644 --- a/platform/mv3/extension/js/background.js +++ b/platform/mv3/extension/js/background.js @@ -88,6 +88,7 @@ import { } from './ruleset-manager.js'; import { + getConsoleOutput, getMatchedRules, isSideloaded, toggleDeveloperMode, @@ -96,7 +97,6 @@ import { } from './debug.js'; import { dnr } from './ext-compat.js'; -import { getTroubleshootingInfo } from './troubleshooting.js'; import { registerInjectables } from './scripting-manager.js'; import { toggleToolbarIcon } from './action.js'; @@ -325,6 +325,12 @@ function onMessage(request, sender, callback) { }); return true; + case 'getEnabledRulesets': + dnr.getEnabledRulesets().then(rulesets => { + callback(rulesets); + }); + return true; + case 'getRulesetDetails': getRulesetDetails().then(rulesetDetails => { callback(Array.from(rulesetDetails.values())); @@ -532,11 +538,9 @@ function onMessage(request, sender, callback) { }); return true; - case 'getTroubleshootingInfo': - getTroubleshootingInfo(request.siteMode).then(info => { - callback(info); - }); - return true; + case 'getConsoleOutput': + callback(getConsoleOutput()); + break; default: break; diff --git a/platform/mv3/extension/js/dashboard.js b/platform/mv3/extension/js/dashboard.js index 1381818a5..bd3560f6f 100644 --- a/platform/mv3/extension/js/dashboard.js +++ b/platform/mv3/extension/js/dashboard.js @@ -21,11 +21,8 @@ import { dom, qs$ } from './dom.js'; import { - localRead, - localRemove, - localWrite, + localRead, localRemove, localWrite, runtime, - sendMessage, webextFlavor, } from './ext.js'; import { faIconsInit } from './fa-icons.js'; @@ -60,7 +57,9 @@ localRead('dashboard.activePane').then(pane => { // Update troubleshooting on-demand const tsinfoObserver = new IntersectionObserver(entries => { if ( entries.every(a => a.isIntersecting === false) ) { return; } - sendMessage({ what: 'getTroubleshootingInfo' }).then(config => { + import('./troubleshooting.js').then(module => { + return module.getTroubleshootingInfo(); + }).then(config => { qs$('[data-i18n="supportS5H"] + pre').textContent = config; }); }); diff --git a/platform/mv3/extension/js/report.js b/platform/mv3/extension/js/report.js index 5b00da252..3f5f50e07 100644 --- a/platform/mv3/extension/js/report.js +++ b/platform/mv3/extension/js/report.js @@ -20,6 +20,7 @@ */ import { dom, qs$ } from './dom.js'; +import { getTroubleshootingInfo } from './troubleshooting.js'; import { sendMessage } from './ext.js'; /******************************************************************************/ @@ -92,10 +93,7 @@ async function reportSpecificFilterIssue() { /******************************************************************************/ -sendMessage({ - what: 'getTroubleshootingInfo', - siteMode: reportedPage.mode, -}).then(config => { +getTroubleshootingInfo(reportedPage.mode).then(config => { qs$('[data-i18n="supportS5H"] + pre').textContent = config; dom.on('[data-url]', 'click', ev => { diff --git a/platform/mv3/extension/js/troubleshooting.js b/platform/mv3/extension/js/troubleshooting.js index 9fa28c5f9..58a1a0387 100644 --- a/platform/mv3/extension/js/troubleshooting.js +++ b/platform/mv3/extension/js/troubleshooting.js @@ -19,11 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -import { dnr } from './ext-compat.js'; -import { getConsoleOutput } from './debug.js'; -import { getDefaultFilteringMode } from './mode-manager.js'; -import { getEffectiveUserRules } from './ruleset-manager.js'; -import { runtime } from './ext.js'; +import { runtime, sendMessage } from './ext.js'; /******************************************************************************/ @@ -57,36 +53,43 @@ export async function getTroubleshootingInfo(siteMode) { const manifest = runtime.getManifest(); const [ platformInfo, - rulesets, + defaultConfig, + enabledRulesets, defaultMode, userRules, + consoleOutput, ] = await Promise.all([ runtime.getPlatformInfo(), - dnr.getEnabledRulesets(), - getDefaultFilteringMode(), - getEffectiveUserRules(), + sendMessage({ what: 'getDefaultConfig' }), + sendMessage({ what: 'getEnabledRulesets' }), + sendMessage({ what: 'getDefaultFilteringMode' }), + sendMessage({ what: 'getEffectiveUserRules' }), + sendMessage({ what: 'getConsoleOutput' }), ]); const browser = (( ) => { const extURL = runtime.getURL(''); - let agent = ''; + let agent = '', version = '?'; if ( extURL.startsWith('moz-extension:') ) { agent = 'Firefox'; + const match = /\bFirefox\/(\d+\.\d+)\b/.exec(navigator.userAgent); + version = match && match[1] || '?'; } else if ( extURL.startsWith('safari-web-extension:') ) { agent = 'Safari'; + const match = /\bVersion\/(\d+\.\d+)\b/.exec(navigator.userAgent); + version = match && match[1] || '?'; } else if ( /\bEdg\/\b/.test(navigator.userAgent) ) { agent = 'Edge'; + const match = /\bEdg\/(\d+)\b/.exec(navigator.userAgent); + version = match && match[1] || '?'; } else { agent = 'Chrome'; + const match = /\bChrome\/(\d+)\b/.exec(navigator.userAgent); + version = match && match[1] || '?'; } if ( /\bMobile\b/.test(navigator.userAgent) ) { agent += ' Mobile'; } - const reVersion = new RegExp(`\\b${agent.slice(0,3)}[^/]*/(\\d+)`); - const match = reVersion.exec(navigator.userAgent); - if ( match ) { - agent += ` ${match[1]}`; - } - agent += ` (${platformInfo.os})` + agent += ` ${version} (${platformInfo.os})` return agent; })(); const modes = [ 'no filtering', 'basic', 'optimal', 'complete' ]; @@ -104,8 +107,17 @@ export async function getTroubleshootingInfo(siteMode) { if ( userRules.length !== 0 ) { config['user rules'] = userRules.length; } - config.rulesets = rulesets; - const consoleOutput = getConsoleOutput(); + const defaultRulesets = defaultConfig.rulesets; + for ( let i = 0; i < enabledRulesets.length; i++ ) { + const id = enabledRulesets[i]; + if ( defaultRulesets.includes(id) ) { continue; } + enabledRulesets[i] = `+${id}`; + } + for ( const id of defaultRulesets ) { + if ( enabledRulesets.includes(id) ) { continue; } + enabledRulesets.push(`-${id}`); + } + config.rulesets = enabledRulesets.sort(); if ( consoleOutput.length !== 0 ) { config.console = siteMode ? consoleOutput.slice(-8)