Skip to content

Commit c6de97c

Browse files
committed
[mv3] Add to troubleshooting info
1 parent f36dd34 commit c6de97c

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

platform/mv3/extension/js/background.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ function onMessage(request, sender, callback) {
402402
});
403403
return true;
404404

405+
case 'getShowBlockedCount':
406+
callback(rulesetConfig.showBlockedCount);
407+
break;
408+
405409
case 'setShowBlockedCount':
406410
rulesetConfig.showBlockedCount = request.state && true || false;
407411
if ( canShowBlockedCount ) {
@@ -595,6 +599,12 @@ function onMessage(request, sender, callback) {
595599
});
596600
return true;
597601

602+
case 'getRegisteredContentScripts':
603+
scrmgr.getRegisteredContentScripts().then(ids => {
604+
callback(ids);
605+
});
606+
return true;
607+
598608
case 'getConsoleOutput':
599609
callback(getConsoleOutput());
600610
break;
@@ -667,7 +677,7 @@ async function startSession() {
667677
// Permissions may have been removed while the extension was disabled
668678
const permissionsUpdated = await syncWithBrowserPermissions();
669679

670-
if ( isNewVersion || permissionsUpdated ) {
680+
if ( isNewVersion || permissionsUpdated || isSideloaded ) {
671681
registerInjectables();
672682
}
673683

platform/mv3/extension/js/popup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ dom.on('#gotoReport', 'click', ev => {
235235
}
236236
if ( url === undefined ) { return; }
237237
const reportURL = new URL(runtime.getURL('/report.html'));
238+
reportURL.searchParams.set('tabid', currentTab.id);
238239
reportURL.searchParams.set('url', tabURL.href);
239240
reportURL.searchParams.set('mode', popupPanelData.level);
240241
sendMessage({

platform/mv3/extension/js/report.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const reportedPage = (( ) => {
5151
return {
5252
hostname: parsedURL.hostname.replace(/^(m|mobile|www)\./, ''),
5353
mode: url.searchParams.get('mode'),
54+
tabId: parseInt(url.searchParams.get('tabid'), 10) || 0,
5455
};
5556
} catch {
5657
}
@@ -93,7 +94,7 @@ async function reportSpecificFilterIssue() {
9394

9495
/******************************************************************************/
9596

96-
getTroubleshootingInfo(reportedPage.mode).then(config => {
97+
getTroubleshootingInfo(reportedPage).then(config => {
9798
qs$('[data-i18n="supportS5H"] + pre').textContent = config;
9899

99100
dom.on('[data-url]', 'click', ev => {

platform/mv3/extension/js/ruleset-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ async function updateSessionRules() {
352352
let ruleId = 1;
353353
for ( const rule of addRulesUnfiltered ) {
354354
rule.id = ruleId++;
355-
if ( Boolean(rule?.condition.regexFilter) === false ) { continue; }
355+
if ( Boolean(rule.condition.regexFilter) === false ) { continue; }
356356
regexCount += 1;
357357
if ( regexCount < maxRegexCount ) { continue; }
358358
rule.id = 0;

platform/mv3/extension/js/scripting-manager.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ export async function registerInjectables() {
423423

424424
/******************************************************************************/
425425

426+
export async function getRegisteredContentScripts() {
427+
const scripts = await browser.scripting.getRegisteredContentScripts()
428+
.catch(( ) => []);
429+
return scripts.map(a => a.id);
430+
}
431+
432+
/******************************************************************************/
433+
426434
export async function onWakeupRun() {
427435
const cleanupTime = await sessionRead('scripting.manager.cleanup.time') || 0;
428436
const now = Date.now();

platform/mv3/extension/js/troubleshooting.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Home: https://github.com/gorhill/uBlock
2020
*/
2121

22-
import { runtime, sendMessage } from './ext.js';
22+
import { browser, runtime, sendMessage } from './ext.js';
2323

2424
/******************************************************************************/
2525

@@ -49,7 +49,7 @@ function renderData(data, depth = 0) {
4949

5050
/******************************************************************************/
5151

52-
export async function getTroubleshootingInfo(siteMode) {
52+
export async function getTroubleshootingInfo(details) {
5353
const manifest = runtime.getManifest();
5454
const [
5555
platformInfo,
@@ -58,6 +58,8 @@ export async function getTroubleshootingInfo(siteMode) {
5858
defaultMode,
5959
userRules,
6060
consoleOutput,
61+
showBlockedCount,
62+
registeredScripts,
6163
hasOmnipotence,
6264
] = await Promise.all([
6365
runtime.getPlatformInfo(),
@@ -66,9 +68,11 @@ export async function getTroubleshootingInfo(siteMode) {
6668
sendMessage({ what: 'getDefaultFilteringMode' }),
6769
sendMessage({ what: 'getEffectiveUserRules' }),
6870
sendMessage({ what: 'getConsoleOutput' }),
71+
sendMessage({ what: 'getShowBlockedCount' }),
72+
sendMessage({ what: 'getRegisteredContentScripts' }),
6973
sendMessage({ what: 'hasBroadHostPermissions' }),
7074
]);
71-
const browser = (( ) => {
75+
const vendor = (( ) => {
7276
const extURL = runtime.getURL('');
7377
let agent = '', version = '?';
7478
if ( extURL.startsWith('moz-extension:') ) {
@@ -96,17 +100,26 @@ export async function getTroubleshootingInfo(siteMode) {
96100
})();
97101
const modes = [ 'no filtering', 'basic', 'optimal', 'complete' ];
98102
const filtering = {};
99-
if ( siteMode ) {
100-
filtering.site = `${modes[siteMode]}`
103+
if ( details?.siteMode ) {
104+
filtering.site = `${modes[details.siteMode]}`
101105
}
102106
filtering.default = `${modes[defaultMode]}`;
103107
const config = {
104108
name: manifest.name,
105109
version: manifest.version,
106-
browser,
110+
browser: vendor,
107111
filtering,
108112
permission: hasOmnipotence ? 'all' : 'ask',
109113
};
114+
if ( details?.tabId ) {
115+
let badge = '?';
116+
if ( showBlockedCount ) {
117+
badge = await browser.action.getBadgeText({ tabId: details.tabId });
118+
}
119+
if ( badge ) {
120+
config.badge = badge;
121+
}
122+
}
110123
if ( userRules.length !== 0 ) {
111124
config['user rules'] = userRules.length;
112125
}
@@ -121,8 +134,11 @@ export async function getTroubleshootingInfo(siteMode) {
121134
enabledRulesets.push(`-${id}`);
122135
}
123136
config.rulesets = enabledRulesets.sort();
137+
if ( registeredScripts.length !== 0 ) {
138+
config.scripting = registeredScripts;
139+
}
124140
if ( consoleOutput.length !== 0 ) {
125-
config.console = siteMode
141+
config.console = details?.siteMode
126142
? consoleOutput.slice(-8)
127143
: consoleOutput;
128144
}

0 commit comments

Comments
 (0)