From f49c4e254b7137e40516cecced58c76d05f23672 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 22 Sep 2021 09:37:21 -0400 Subject: [PATCH] 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. --- src/js/background.js | 1 + src/js/start.js | 78 +++++++++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 5bb86f021..2858770a2 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -72,6 +72,7 @@ const hiddenSettingsDefault = { filterOnHeaders: false, loggerPopupType: 'popup', manualUpdateAssetFetchPeriod: 500, + modifyWebextFlavor: 'unset', popupFontSize: 'unset', popupPanelDisabledSections: 0, popupPanelLockedSections: 0, diff --git a/src/js/start.js b/src/js/start.js index 1a7398536..a1c50c1fb 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -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 @@ -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`);