mirror of https://github.com/gorhill/uBlock.git
Neutralize `localStorage` access on mobile platform
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/899 window.localStorage is synchronous and thus should be avoided at launch time. Currently the avoidance is only for mobile platforms.
This commit is contained in:
parent
c0947200e5
commit
da0ef9454a
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue