harden chrome.privacy calls: one threw for unknown reasons (can't repro so far)

This commit is contained in:
gorhill 2015-08-13 19:42:30 -04:00
parent 118a7792cc
commit 7a38cd756d

View file

@ -66,6 +66,13 @@ vAPI.storage = chrome.storage.local;
// https://github.com/gorhill/uMatrix/issues/234 // https://github.com/gorhill/uMatrix/issues/234
// https://developer.chrome.com/extensions/privacy#property-network // https://developer.chrome.com/extensions/privacy#property-network
// 2015-08-12: Wrapped Chrome API in try-catch statements. I had a fluke
// event in which it appeared the Chrome 46 decided to restart uBlock (for
// unknown reasons) and again for unknown reasons the browser acted as if
// uBlock did not declare the `privacy` permission in its manifest, putting
// uBlock in a bad, non-fonctional state -- because call to `chrome.privacy`
// API threw an exception.
vAPI.browserSettings = { vAPI.browserSettings = {
set: function(details) { set: function(details) {
for ( var setting in details ) { for ( var setting in details ) {
@ -74,25 +81,37 @@ vAPI.browserSettings = {
} }
switch ( setting ) { switch ( setting ) {
case 'prefetching': case 'prefetching':
chrome.privacy.network.networkPredictionEnabled.set({ try {
value: !!details[setting], chrome.privacy.network.networkPredictionEnabled.set({
scope: 'regular' value: !!details[setting],
}); scope: 'regular'
});
} catch(ex) {
console.error(ex);
}
break; break;
case 'hyperlinkAuditing': case 'hyperlinkAuditing':
chrome.privacy.websites.hyperlinkAuditingEnabled.set({ try {
value: !!details[setting], chrome.privacy.websites.hyperlinkAuditingEnabled.set({
scope: 'regular' value: !!details[setting],
}); scope: 'regular'
});
} catch(ex) {
console.error(ex);
}
break; break;
case 'webrtcIPAddress': case 'webrtcIPAddress':
if ( typeof chrome.privacy.network.webRTCMultipleRoutesEnabled === 'object' ) { if ( typeof chrome.privacy.network.webRTCMultipleRoutesEnabled === 'object' ) {
chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ try {
value: !!details[setting], chrome.privacy.network.webRTCMultipleRoutesEnabled.set({
scope: 'regular' value: !!details[setting],
}); scope: 'regular'
});
} catch(ex) {
console.error(ex);
}
} }
break; break;