mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-02 09:09:38 +02:00
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 = {
|
const options = {
|
||||||
defaultDeviceName: window.navigator.platform,
|
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:
|
// 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) {
|
const push = async function(dataKey, data) {
|
||||||
|
|
||||||
let bin = {
|
let bin = {
|
||||||
'source': options.deviceName || options.defaultDeviceName,
|
'source': getDeviceName() || options.defaultDeviceName,
|
||||||
'tstamp': Date.now(),
|
'tstamp': Date.now(),
|
||||||
'data': data,
|
'data': data,
|
||||||
'size': 0
|
'size': 0
|
||||||
@ -1579,6 +1585,7 @@ vAPI.cloud = (( ) => {
|
|||||||
|
|
||||||
const getOptions = function(callback) {
|
const getOptions = function(callback) {
|
||||||
if ( typeof callback !== 'function' ) { return; }
|
if ( typeof callback !== 'function' ) { return; }
|
||||||
|
getDeviceName();
|
||||||
callback(options);
|
callback(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -226,6 +226,10 @@ vAPI.closePopup = function() {
|
|||||||
// Always use a wrapper to seamlessly handle exceptions
|
// Always use a wrapper to seamlessly handle exceptions
|
||||||
|
|
||||||
vAPI.localStorage = {
|
vAPI.localStorage = {
|
||||||
|
started: vAPI.webextFlavor.soup.has('mobile') === false,
|
||||||
|
start: function() {
|
||||||
|
this.started = true;
|
||||||
|
},
|
||||||
clear: function() {
|
clear: function() {
|
||||||
try {
|
try {
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
@ -233,6 +237,7 @@ vAPI.localStorage = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getItem: function(key) {
|
getItem: function(key) {
|
||||||
|
if ( this.started === false ) { return null; }
|
||||||
try {
|
try {
|
||||||
return window.localStorage.getItem(key);
|
return window.localStorage.getItem(key);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
@ -246,6 +251,7 @@ vAPI.localStorage = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setItem: function(key, value) {
|
setItem: function(key, value) {
|
||||||
|
if ( this.started === false ) { return; }
|
||||||
try {
|
try {
|
||||||
window.localStorage.setItem(key, value);
|
window.localStorage.setItem(key, value);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
|
@ -316,6 +316,10 @@ if ( selfieIsValid !== true ) {
|
|||||||
// Start network observers.
|
// Start network observers.
|
||||||
µb.webRequest.start();
|
µ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
|
// Ensure that the resources allocated for decompression purpose (likely
|
||||||
// large buffers) are garbage-collectable immediately after launch.
|
// large buffers) are garbage-collectable immediately after launch.
|
||||||
// Otherwise I have observed that it may take quite a while before the
|
// Otherwise I have observed that it may take quite a while before the
|
||||||
|
Loading…
Reference in New Issue
Block a user