Skip to content

Commit

Permalink
Add advanced setting to default modify webext flavor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Sep 22, 2021
1 parent 33a18c3 commit f49c4e2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const hiddenSettingsDefault = {
filterOnHeaders: false,
loggerPopupType: 'popup',
manualUpdateAssetFetchPeriod: 500,
modifyWebextFlavor: 'unset',
popupFontSize: 'unset',
popupPanelDisabledSections: 0,
popupPanelLockedSections: 0,
Expand Down
78 changes: 52 additions & 26 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,57 @@ const onCacheSettingsReady = async function(fetched) {

/******************************************************************************/

const onHiddenSettingsReady = async function() {
// Maybe customize webext flavor
if ( µb.hiddenSettings.modifyWebextFlavor !== 'unset' ) {
const tokens = µb.hiddenSettings.modifyWebextFlavor.split(/\s+/);
for ( const token of tokens ) {
switch ( token[0] ) {
case '+':
vAPI.webextFlavor.soup.add(token.slice(1));
break;
case '-':
vAPI.webextFlavor.soup.delete(token.slice(1));
break;
default:
vAPI.webextFlavor.soup.add(token);
break;
}
}
ubolog(`Override default webext flavor with ${tokens}`);
}

// Maybe override current network listener suspend state
if ( µb.hiddenSettings.suspendTabsUntilReady === 'no' ) {
vAPI.net.unsuspend(true);
} else if ( µb.hiddenSettings.suspendTabsUntilReady === 'yes' ) {
vAPI.net.suspend();
}

// Maybe disable WebAssembly
if ( vAPI.canWASM && µb.hiddenSettings.disableWebAssembly !== true ) {
const wasmModuleFetcher = function(path) {
return fetch(`${path}.wasm`, { mode: 'same-origin' }).then(
WebAssembly.compileStreaming
).catch(reason => {
ubolog(reason);
});
};
staticNetFilteringEngine.enableWASM(wasmModuleFetcher, './js/wasm/').then(result => {
if ( result !== true ) { return; }
ubolog(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
});
}

// Matbe override default cache storage
const cacheBackend = await cacheStorage.select(
µb.hiddenSettings.cacheStorageAPI
);
ubolog(`Backend storage for cache will be ${cacheBackend}`);
};

/******************************************************************************/

const onFirstFetchReady = function(fetched, adminExtra) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/507
// Firefox-specific: somehow `fetched` is undefined under certain
Expand Down Expand Up @@ -327,34 +378,9 @@ try {
ubolog(`Admin settings ready ${Date.now()-vAPI.T0} ms after launch`);

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

// Maybe override current network listener suspend state
if ( µb.hiddenSettings.suspendTabsUntilReady === 'no' ) {
vAPI.net.unsuspend(true);
} else if ( µb.hiddenSettings.suspendTabsUntilReady === 'yes' ) {
vAPI.net.suspend();
}

if ( vAPI.canWASM && µb.hiddenSettings.disableWebAssembly !== true ) {
const wasmModuleFetcher = function(path) {
return fetch(`${path}.wasm`, { mode: 'same-origin' }).then(
WebAssembly.compileStreaming
).catch(reason => {
ubolog(reason);
});
};
staticNetFilteringEngine.enableWASM(wasmModuleFetcher, './js/wasm/').then(result => {
if ( result !== true ) { return; }
ubolog(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
});
}

const cacheBackend = await cacheStorage.select(
µb.hiddenSettings.cacheStorageAPI
);
ubolog(`Backend storage for cache will be ${cacheBackend}`);

const adminExtra = await vAPI.adminStorage.get('toAdd');
ubolog(`Extra admin settings ready ${Date.now()-vAPI.T0} ms after launch`);

Expand Down

0 comments on commit f49c4e2

Please sign in to comment.