diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index fd4f027a7..c3ad46944 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -1443,7 +1443,14 @@ vAPI.cloud = (( ) => { const options = { defaultDeviceName: window.navigator.platform, - deviceName: vAPI.localStorage.getItem('deviceName') || '' + deviceName: undefined, + }; + + const getDeviceName = function() { + if ( options.deviceName === undefined ) { + options.deviceName = vAPI.localStorage.getItem('deviceName') || ''; + } + return options.deviceName; }; // This is used to find out a rough count of how many chunks exists: @@ -1491,9 +1498,8 @@ vAPI.cloud = (( ) => { }; const push = async function(dataKey, data) { - let bin = { - 'source': options.deviceName || options.defaultDeviceName, + 'source': getDeviceName() || options.defaultDeviceName, 'tstamp': Date.now(), 'data': data, 'size': 0 @@ -1579,6 +1585,7 @@ vAPI.cloud = (( ) => { const getOptions = function(callback) { if ( typeof callback !== 'function' ) { return; } + getDeviceName(); callback(options); }; diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index dcd11d36f..136e4a02d 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -226,6 +226,10 @@ vAPI.closePopup = function() { // Always use a wrapper to seamlessly handle exceptions vAPI.localStorage = { + started: vAPI.webextFlavor.soup.has('mobile') === false, + start: function() { + this.started = true; + }, clear: function() { try { window.localStorage.clear(); @@ -233,6 +237,7 @@ vAPI.localStorage = { } }, getItem: function(key) { + if ( this.started === false ) { return null; } try { return window.localStorage.getItem(key); } catch(ex) { @@ -246,6 +251,7 @@ vAPI.localStorage = { } }, setItem: function(key, value) { + if ( this.started === false ) { return; } try { window.localStorage.setItem(key, value); } catch(ex) { diff --git a/src/js/start.js b/src/js/start.js index d623bfe06..b6f3be446 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -316,6 +316,10 @@ if ( selfieIsValid !== true ) { // Start network observers. µb.webRequest.start(); +// https://github.com/uBlockOrigin/uBlock-issues/issues/899 +// Signal that localStorage can be used now that uBO is ready. +vAPI.localStorage.start(); + // Ensure that the resources allocated for decompression purpose (likely // large buffers) are garbage-collectable immediately after launch. // Otherwise I have observed that it may take quite a while before the