From 9bcfc8ff1c614b1c4ded9cc4ca8e5c1f283bcee4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 24 Jun 2025 17:19:49 -0400 Subject: [PATCH] [mv3] Add access to troubleshooting info in About pane --- platform/mv3/extension/dashboard.html | 4 + platform/mv3/extension/js/dashboard.js | 7 +- platform/mv3/extension/js/report.js | 109 +--------------- platform/mv3/extension/js/troubleshooting.js | 123 +++++++++++++++++++ platform/mv3/extension/report.html | 2 +- 5 files changed, 138 insertions(+), 107 deletions(-) create mode 100644 platform/mv3/extension/js/troubleshooting.js diff --git a/platform/mv3/extension/dashboard.html b/platform/mv3/extension/dashboard.html index ee64de6bf..bc71b3398 100644 --- a/platform/mv3/extension/dashboard.html +++ b/platform/mv3/extension/dashboard.html @@ -140,6 +140,10 @@
Flags of the World by David Krmela
CodeMirror 6 by Marijn Haverbeke
+
+
+

+            
diff --git a/platform/mv3/extension/js/dashboard.js b/platform/mv3/extension/js/dashboard.js index d5c27078e..113d7481f 100644 --- a/platform/mv3/extension/js/dashboard.js +++ b/platform/mv3/extension/js/dashboard.js @@ -19,13 +19,14 @@ Home: https://github.com/gorhill/uBlock */ +import { dom, qs$ } from './dom.js'; import { localRead, localRemove, localWrite, } from './ext.js'; -import { dom } from './dom.js'; +import { getTroubleshootingInfo } from './troubleshooting.js'; import { runtime } from './ext.js'; /******************************************************************************/ @@ -52,6 +53,10 @@ localRead('dashboard.activePane').then(pane => { dom.body.dataset.pane = pane; }); +getTroubleshootingInfo().then(config => { + qs$('[data-i18n="supportS5H"] + pre').textContent = config; +}); + /******************************************************************************/ export function hashFromIterable(iter) { diff --git a/platform/mv3/extension/js/report.js b/platform/mv3/extension/js/report.js index 126d251d8..3f5f50e07 100644 --- a/platform/mv3/extension/js/report.js +++ b/platform/mv3/extension/js/report.js @@ -19,18 +19,9 @@ Home: https://github.com/gorhill/uBlock */ -import { - dom, - qs$, -} from './dom.js'; - -import { - localRead, - runtime, - sendMessage, -} from './ext.js'; - -import { dnr } from './ext-compat.js'; +import { dom, qs$ } from './dom.js'; +import { getTroubleshootingInfo } from './troubleshooting.js'; +import { sendMessage } from './ext.js'; /******************************************************************************/ @@ -74,98 +65,6 @@ function reportSpecificFilterType() { /******************************************************************************/ -function renderData(data, depth = 0) { - const indent = ' '.repeat(depth); - if ( Array.isArray(data) ) { - const out = []; - for ( const value of data ) { - out.push(renderData(value, depth)); - } - return out.join('\n'); - } - if ( typeof data !== 'object' || data === null ) { - return `${indent}${data}`; - } - const out = []; - for ( const [ name, value ] of Object.entries(data) ) { - if ( typeof value === 'object' && value !== null ) { - out.push(`${indent}${name}:`); - out.push(renderData(value, depth + 1)); - continue; - } - out.push(`${indent}${name}: ${value}`); - } - return out.join('\n'); -} - -/******************************************************************************/ - -async function getConfigData() { - const manifest = runtime.getManifest(); - const [ - platformInfo, - rulesets, - defaultMode, - userRules, - registerContentScriptsReason, - unregisterContentScriptsReason, - ] = await Promise.all([ - runtime.getPlatformInfo(), - dnr.getEnabledRulesets(), - sendMessage({ what: 'getDefaultFilteringMode' }), - sendMessage({ what: 'getEffectiveUserRules' }), - localRead('$scripting.registerContentScripts'), - localRead('$scripting.unregisterContentScripts'), - ]); - const browser = (( ) => { - const extURL = runtime.getURL(''); - let agent = ''; - if ( extURL.startsWith('moz-extension:') ) { - agent = 'Firefox'; - } else if ( extURL.startsWith('safari-web-extension:') ) { - agent = 'Safari'; - } else if ( /\bEdg\/\b/.test(navigator.userAgent) ) { - agent = 'Edge'; - } else { - agent = 'Chrome'; - } - dom.cl.add('html', agent.toLowerCase()); - 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})` - return agent; - })(); - const modes = [ 'no filtering', 'basic', 'optimal', 'complete' ]; - const config = { - name: manifest.name, - version: manifest.version, - browser, - filtering: { - 'site': `${modes[reportedPage.mode]}`, - 'default': `${modes[defaultMode]}`, - }, - }; - if ( userRules.length !== 0 ) { - config['user rules'] = userRules.length; - } - config.rulesets = rulesets; - if ( registerContentScriptsReason !== undefined ) { - config.registerContentScripts = registerContentScriptsReason; - } - if ( unregisterContentScriptsReason !== undefined ) { - config.unregisterContentScripts = unregisterContentScriptsReason; - } - return renderData(config); -} - -/******************************************************************************/ - async function reportSpecificFilterIssue() { const githubURL = new URL( 'https://github.com/uBlockOrigin/uAssets/issues/new?template=specific_report_from_ubol.yml' @@ -194,7 +93,7 @@ async function reportSpecificFilterIssue() { /******************************************************************************/ -getConfigData().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 new file mode 100644 index 000000000..4300d1eb1 --- /dev/null +++ b/platform/mv3/extension/js/troubleshooting.js @@ -0,0 +1,123 @@ +/******************************************************************************* + + uBlock Origin - a comprehensive, efficient content blocker + Copyright (C) 2024-present Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +import { + localRead, + runtime, + sendMessage, +} from './ext.js'; + +import { dnr } from './ext-compat.js'; +import { dom } from './dom.js'; + +/******************************************************************************/ + +function renderData(data, depth = 0) { + const indent = ' '.repeat(depth); + if ( Array.isArray(data) ) { + const out = []; + for ( const value of data ) { + out.push(renderData(value, depth)); + } + return out.join('\n'); + } + if ( typeof data !== 'object' || data === null ) { + return `${indent}${data}`; + } + const out = []; + for ( const [ name, value ] of Object.entries(data) ) { + if ( typeof value === 'object' && value !== null ) { + out.push(`${indent}${name}:`); + out.push(renderData(value, depth + 1)); + continue; + } + out.push(`${indent}${name}: ${value}`); + } + return out.join('\n'); +} + +/******************************************************************************/ + +export async function getTroubleshootingInfo(siteMode) { + const manifest = runtime.getManifest(); + const [ + platformInfo, + rulesets, + defaultMode, + userRules, + registerContentScriptsReason, + unregisterContentScriptsReason, + ] = await Promise.all([ + runtime.getPlatformInfo(), + dnr.getEnabledRulesets(), + sendMessage({ what: 'getDefaultFilteringMode' }), + sendMessage({ what: 'getEffectiveUserRules' }), + localRead('$scripting.registerContentScripts'), + localRead('$scripting.unregisterContentScripts'), + ]); + const browser = (( ) => { + const extURL = runtime.getURL(''); + let agent = ''; + if ( extURL.startsWith('moz-extension:') ) { + agent = 'Firefox'; + } else if ( extURL.startsWith('safari-web-extension:') ) { + agent = 'Safari'; + } else if ( /\bEdg\/\b/.test(navigator.userAgent) ) { + agent = 'Edge'; + } else { + agent = 'Chrome'; + } + dom.cl.add('html', agent.toLowerCase()); + 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})` + return agent; + })(); + const modes = [ 'no filtering', 'basic', 'optimal', 'complete' ]; + const filtering = {}; + if ( siteMode ) { + filtering.site = `${modes[siteMode]}` + } + filtering.default = `${modes[defaultMode]}`; + const config = { + name: manifest.name, + version: manifest.version, + browser, + filtering, + }; + if ( userRules.length !== 0 ) { + config['user rules'] = userRules.length; + } + config.rulesets = rulesets; + if ( registerContentScriptsReason !== undefined ) { + config.registerContentScripts = registerContentScriptsReason; + } + if ( unregisterContentScriptsReason !== undefined ) { + config.unregisterContentScripts = unregisterContentScriptsReason; + } + return renderData(config); +} diff --git a/platform/mv3/extension/report.html b/platform/mv3/extension/report.html index 8632097f7..cf15492d7 100644 --- a/platform/mv3/extension/report.html +++ b/platform/mv3/extension/report.html @@ -55,7 +55,7 @@

-

+