Skip to content

Commit f49c4e2

Browse files
committed
Add advanced setting to default modify webext flavor
Name: modifyWebextFlavor Value: A list of space-separated tokens to be added/removed from the computed default webext flavor. The primary purpose is to give filter list authors the ability to test mobile flavor on desktop computers. Though mobile versions of web pages can be emulated using browser dev tools, it's not possible to do so for uBO itself. By using `+mobile` as a value for this setting will force uBO to act as if it's being executed on a mobile device. Important: this setting is best used in a dedicated browser profile, as this affects how filter lists are compiled. So best to set it in a new browser profile, then force all filter lists to be recompiled, and use the profile in the future when there is a need to test the specific webext flavor.
1 parent 33a18c3 commit f49c4e2

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

src/js/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const hiddenSettingsDefault = {
7272
filterOnHeaders: false,
7373
loggerPopupType: 'popup',
7474
manualUpdateAssetFetchPeriod: 500,
75+
modifyWebextFlavor: 'unset',
7576
popupFontSize: 'unset',
7677
popupPanelDisabledSections: 0,
7778
popupPanelLockedSections: 0,

src/js/start.js

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,57 @@ const onCacheSettingsReady = async function(fetched) {
248248

249249
/******************************************************************************/
250250

251+
const onHiddenSettingsReady = async function() {
252+
// Maybe customize webext flavor
253+
if ( µb.hiddenSettings.modifyWebextFlavor !== 'unset' ) {
254+
const tokens = µb.hiddenSettings.modifyWebextFlavor.split(/\s+/);
255+
for ( const token of tokens ) {
256+
switch ( token[0] ) {
257+
case '+':
258+
vAPI.webextFlavor.soup.add(token.slice(1));
259+
break;
260+
case '-':
261+
vAPI.webextFlavor.soup.delete(token.slice(1));
262+
break;
263+
default:
264+
vAPI.webextFlavor.soup.add(token);
265+
break;
266+
}
267+
}
268+
ubolog(`Override default webext flavor with ${tokens}`);
269+
}
270+
271+
// Maybe override current network listener suspend state
272+
if ( µb.hiddenSettings.suspendTabsUntilReady === 'no' ) {
273+
vAPI.net.unsuspend(true);
274+
} else if ( µb.hiddenSettings.suspendTabsUntilReady === 'yes' ) {
275+
vAPI.net.suspend();
276+
}
277+
278+
// Maybe disable WebAssembly
279+
if ( vAPI.canWASM && µb.hiddenSettings.disableWebAssembly !== true ) {
280+
const wasmModuleFetcher = function(path) {
281+
return fetch(`${path}.wasm`, { mode: 'same-origin' }).then(
282+
WebAssembly.compileStreaming
283+
).catch(reason => {
284+
ubolog(reason);
285+
});
286+
};
287+
staticNetFilteringEngine.enableWASM(wasmModuleFetcher, './js/wasm/').then(result => {
288+
if ( result !== true ) { return; }
289+
ubolog(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
290+
});
291+
}
292+
293+
// Matbe override default cache storage
294+
const cacheBackend = await cacheStorage.select(
295+
µb.hiddenSettings.cacheStorageAPI
296+
);
297+
ubolog(`Backend storage for cache will be ${cacheBackend}`);
298+
};
299+
300+
/******************************************************************************/
301+
251302
const onFirstFetchReady = function(fetched, adminExtra) {
252303
// https://github.com/uBlockOrigin/uBlock-issues/issues/507
253304
// Firefox-specific: somehow `fetched` is undefined under certain
@@ -327,34 +378,9 @@ try {
327378
ubolog(`Admin settings ready ${Date.now()-vAPI.T0} ms after launch`);
328379

329380
await µb.loadHiddenSettings();
381+
onHiddenSettingsReady();
330382
ubolog(`Hidden settings ready ${Date.now()-vAPI.T0} ms after launch`);
331383

332-
// Maybe override current network listener suspend state
333-
if ( µb.hiddenSettings.suspendTabsUntilReady === 'no' ) {
334-
vAPI.net.unsuspend(true);
335-
} else if ( µb.hiddenSettings.suspendTabsUntilReady === 'yes' ) {
336-
vAPI.net.suspend();
337-
}
338-
339-
if ( vAPI.canWASM && µb.hiddenSettings.disableWebAssembly !== true ) {
340-
const wasmModuleFetcher = function(path) {
341-
return fetch(`${path}.wasm`, { mode: 'same-origin' }).then(
342-
WebAssembly.compileStreaming
343-
).catch(reason => {
344-
ubolog(reason);
345-
});
346-
};
347-
staticNetFilteringEngine.enableWASM(wasmModuleFetcher, './js/wasm/').then(result => {
348-
if ( result !== true ) { return; }
349-
ubolog(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
350-
});
351-
}
352-
353-
const cacheBackend = await cacheStorage.select(
354-
µb.hiddenSettings.cacheStorageAPI
355-
);
356-
ubolog(`Backend storage for cache will be ${cacheBackend}`);
357-
358384
const adminExtra = await vAPI.adminStorage.get('toAdd');
359385
ubolog(`Extra admin settings ready ${Date.now()-vAPI.T0} ms after launch`);
360386

0 commit comments

Comments
 (0)