diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 7c270038a..3014ca2f3 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -75,6 +75,12 @@ vAPI.storage = chrome.storage.local; vAPI.browserSettings = { webRTCSupported: undefined, + // https://github.com/gorhill/uBlock/issues/875 + // Must not leave `lastError` unchecked. + noopCallback: function() { + void chrome.runtime.lastError; + }, + // https://github.com/gorhill/uBlock/issues/533 // We must first check wether this Chromium-based browser was compiled // with WebRTC support. To do this, we use an iframe, this way the @@ -121,30 +127,35 @@ vAPI.browserSettings = { return; } - // Older version of Chromium do not support this setting. - if ( typeof chrome.privacy.network.webRTCMultipleRoutesEnabled !== 'object' ) { - return; + var cp = chrome.privacy, cpi = cp.IPHandlingPolicy, cpn = cp.network; + + // Older version of Chromium do not support this setting, and is + // marked as "deprecated" since Chromium 48. + if ( typeof cpn.webRTCMultipleRoutesEnabled === 'object' ) { + try { + cpn.webRTCMultipleRoutesEnabled.set({ + value: !!setting, + scope: 'regular' + }, this.noopCallback); + } catch(ex) { + console.error(ex); + } } - try { - chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ - value: !!setting, - scope: 'regular' - }, function() { - void chrome.runtime.lastError; - }); - } catch(ex) { - console.error(ex); + // This setting became available in Chromium 48. + if ( typeof cpn.webRTCIPHandlingPolicy === 'object' ) { + try { + cpn.webRTCIPHandlingPolicy.set({ + value: !!setting ? cpi.DEFAULT : cpi.DEFAULT_PUBLIC_INTERFACE_ONLY, + scope: 'regular' + }, this.noopCallback); + } catch(ex) { + console.error(ex); + } } }, set: function(details) { - // https://github.com/gorhill/uBlock/issues/875 - // Must not leave `lastError` unchecked. - var callback = function() { - void chrome.runtime.lastError; - }; - for ( var setting in details ) { if ( details.hasOwnProperty(setting) === false ) { continue; @@ -155,7 +166,7 @@ vAPI.browserSettings = { chrome.privacy.network.networkPredictionEnabled.set({ value: !!details[setting], scope: 'regular' - }, callback); + }, this.noopCallback); } catch(ex) { console.error(ex); } @@ -166,7 +177,7 @@ vAPI.browserSettings = { chrome.privacy.websites.hyperlinkAuditingEnabled.set({ value: !!details[setting], scope: 'regular' - }, callback); + }, this.noopCallback); } catch(ex) { console.error(ex); }