From 03afd4031f7d1eb73395bc5be751898f80797b94 Mon Sep 17 00:00:00 2001 From: Aaron Horler Date: Wed, 11 Apr 2018 13:18:17 +1000 Subject: [PATCH] Automatic option saving, removal of all HTM4, and minor formatting changes. This commit makes no functional change, but will be released. --- html/options.html | 122 +++++++++---------- js/background.js | 82 ++++++------- js/options.js | 295 +++++++++++++++++++++++----------------------- manifest.json | 42 +++---- 4 files changed, 272 insertions(+), 269 deletions(-) diff --git a/html/options.html b/html/options.html index f0274f9..a279b38 100644 --- a/html/options.html +++ b/html/options.html @@ -1,73 +1,73 @@ - - WebRTC Leak Prevent - - -

Advanced options

+ + WebRTC Leak Prevent + + +

Advanced options

-
-
-

- WebRTC IP handling policy -

-

- - -

-
+
+
+

+ WebRTC IP handling policy +

+

+ + +

+
-
-

- Legacy options -

-

- -
- (Supported from Chromium version 42, and depreciated from version 48) -

-

- -
- (Supported from Chromium version 47, and depreciated from version 48) -

-
+
+

+ Legacy options +

+

+ +
+ (Supported from Chromium version 42, and depreciated from version 48) +

+

+ +
+ (Supported from Chromium version 47, and depreciated from version 48) +

+
-

- What do these options mean? -

-
+

+ What do these options mean? +

+
-
-

This version of Chromium is incompatible with the required WebRTC privacy options.

-
+
+

This version of Chromium is incompatible with the required WebRTC privacy options.

+
-
- Incognito protection - -

Enabled

- -

- Not enabled. Learn more. -

-
+
+ Incognito protection -

- - - +

Enabled

- -

+

+ Not enabled. Learn more. +

+
-

- Developed by Aaron Horler (aghorler) | GitHub source -

+

+ + + - - + +

+ +

+ Developed by Aaron Horler (aghorler) | GitHub source +

+ + + diff --git a/js/background.js b/js/background.js index af5b3b1..447befd 100644 --- a/js/background.js +++ b/js/background.js @@ -1,56 +1,56 @@ /* Function to get version of Chrome. https://stackoverflow.com/a/4900484 */ function getMajorVerison(){ - var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); - return raw ? parseInt(raw[2], 10) : false; + var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + return raw ? parseInt(raw[2], 10) : false; } /* Configure WebRTC leak prevention default setting, depending on Chrome version. */ chrome.storage.local.get(null, function(items){ - /* Use webRTCIPHandlingPolicy in newer versions of Chrome. */ - if(getMajorVerison() > 47){ - if(items.rtcIPHandling == undefined){ - try{ - chrome.storage.local.set({ - rtcIPHandling: 'default_public_interface_only' - }, function(){ - chrome.privacy.network.webRTCIPHandlingPolicy.set({ - value: 'default_public_interface_only' - }); - }) - } - catch(e){ - console.log("Error: " + e.message); - } - } - } - /* Use webRTCMultipleRoutesEnabled in older versions of Chrome. */ - else if(getMajorVerison() > 41 && getMajorVerison() < 48){ - if(items.rtcMultipleRoutes == undefined){ - try{ - chrome.storage.local.set({ - rtcMultipleRoutes: true - }, function(){ - chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ - value: false, - scope: 'regular' - }); - }) - } - catch(e){ - console.log("Error: " + e.message); - } - } - } + /* Use webRTCIPHandlingPolicy in newer versions of Chrome. */ + if(getMajorVerison() > 47){ + if(items.rtcIPHandling == undefined){ + try{ + chrome.storage.local.set({ + rtcIPHandling: 'default_public_interface_only' + }, function(){ + chrome.privacy.network.webRTCIPHandlingPolicy.set({ + value: 'default_public_interface_only' + }); + }) + } + catch(e){ + console.log("Error: " + e.message); + } + } + } + /* Use webRTCMultipleRoutesEnabled in older versions of Chrome. */ + else if(getMajorVerison() > 41 && getMajorVerison() < 48){ + if(items.rtcMultipleRoutes == undefined){ + try{ + chrome.storage.local.set({ + rtcMultipleRoutes: true + }, function(){ + chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ + value: false, + scope: 'regular' + }); + }) + } + catch(e){ + console.log("Error: " + e.message); + } + } + } }); /* Open options page on install. */ chrome.runtime.onInstalled.addListener(function(details){ - if(details.reason == "install"){ - chrome.runtime.openOptionsPage(); - } + if(details.reason == "install"){ + chrome.runtime.openOptionsPage(); + } }); /* Open options page on toolbar icon click. */ chrome.browserAction.onClicked.addListener(function(){ - chrome.runtime.openOptionsPage(); + chrome.runtime.openOptionsPage(); }); diff --git a/js/options.js b/js/options.js index 8231c24..cea2037 100644 --- a/js/options.js +++ b/js/options.js @@ -1,172 +1,175 @@ /* Function to get version of Chrome. https://stackoverflow.com/a/4900484 */ function getMajorVerison(){ - var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); - return raw ? parseInt(raw[2], 10) : false; + var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + return raw ? parseInt(raw[2], 10) : false; } /* Function to determine if extension is allowed to run in Incognito mode. */ function testIncognito(){ - chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess){ - var incognitoAllowed = document.getElementById('incognitoAllowed'); - var incognitoDisallowed = document.getElementById('incognitoDisallowed'); + chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess){ + var incognitoAllowed = document.getElementById('incognitoAllowed'); + var incognitoDisallowed = document.getElementById('incognitoDisallowed'); - if(isAllowedAccess){ - incognitoDisallowed.style.display = 'none'; - } - else{ - incognitoAllowed.style.display = 'none'; - } - }); + if(isAllowedAccess){ + incognitoDisallowed.style.display = 'none'; + } + else{ + incognitoAllowed.style.display = 'none'; + } + }); } /* Function to display setting page content, depending on Chrome version. */ function displayContent(){ - var divContent = document.getElementById('content'); - var divNew = document.getElementById('new'); - var divLegacy = document.getElementById('legacy'); - var pLegacyProxy = document.getElementById('legacyProxy'); - var divFail = document.getElementById('fail'); - var divIncognito = document.getElementById('incognito'); - var divApply = document.getElementById('applyButton'); + var divContent = document.getElementById('content'); + var divNew = document.getElementById('new'); + var divLegacy = document.getElementById('legacy'); + var pLegacyProxy = document.getElementById('legacyProxy'); + var divFail = document.getElementById('fail'); + var divIncognito = document.getElementById('incognito'); + var divApply = document.getElementById('applyButton'); - if(getMajorVerison() > 47){ - divLegacy.style.display = 'none'; - divFail.style.display = 'none'; - testIncognito(); - } - else if(getMajorVerison() > 41 && getMajorVerison() < 47){ - divNew.style.display = 'none'; - divFail.style.display = 'none'; - pLegacyProxy.style.display = 'none'; - testIncognito(); - } - else if(getMajorVerison() == 47){ - divNew.style.display = 'none'; - divFail.style.display = 'none'; - testIncognito(); - } - else{ - divContent.style.display = 'none'; - divIncognito.style.display = 'none'; - divApply.style.display = 'none'; - } + if(getMajorVerison() > 47){ + divLegacy.style.display = 'none'; + divFail.style.display = 'none'; + testIncognito(); + } + else if(getMajorVerison() > 41 && getMajorVerison() < 47){ + divNew.style.display = 'none'; + divFail.style.display = 'none'; + pLegacyProxy.style.display = 'none'; + testIncognito(); + } + else if(getMajorVerison() == 47){ + divNew.style.display = 'none'; + divFail.style.display = 'none'; + testIncognito(); + } + else{ + divContent.style.display = 'none'; + divIncognito.style.display = 'none'; + divApply.style.display = 'none'; + } } /* Function to save and set options. */ function saveOptions(){ - if(getMajorVerison() > 47){ - var policy = document.getElementById('policy').value; - chrome.storage.local.set({ - rtcIPHandling: policy - }, function(){ - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - status.style.color = "green"; - try{ - chrome.storage.local.get('rtcIPHandling', function(items){ - chrome.privacy.network.webRTCIPHandlingPolicy.set({ - value: items.rtcIPHandling - }); - }); - } - catch(e){ - status.textContent = 'Error.'; - status.style.color = "red"; - console.log("Error: " + e.message); - } - setTimeout(function(){ - status.textContent = ''; - }, 750); - }); - } - else if(getMajorVerison() > 41 && getMajorVerison() < 47){ - var rtcMultipleRoutes = document.getElementById('multipleroutes').checked; - chrome.storage.local.set({ - rtcMultipleRoutes: rtcMultipleRoutes - }, function(){ - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - status.style.color = "green"; - try{ - chrome.storage.local.get('rtcMultipleRoutes', function(items){ - chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ - value: !items.rtcMultipleRoutes, - scope: 'regular' - }); - }); - } - catch(e){ - status.textContent = 'Error.'; - status.style.color = "red"; - console.log("Error: " + e.message); - } - setTimeout(function(){ - status.textContent = ''; - }, 750); - }); - } - else if(getMajorVerison() == 47){ - var nonProxiedUDP = document.getElementById('proxy').checked; - var rtcMultipleRoutes = document.getElementById('multipleroutes').checked; - chrome.storage.local.set({ - nonProxiedUDP: nonProxiedUDP, - rtcMultipleRoutes: rtcMultipleRoutes - }, function(){ - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - status.style.color = "green"; - try{ - chrome.storage.local.get(null, function(items){ - chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ - value: !items.rtcMultipleRoutes, - scope: 'regular' - }); - chrome.privacy.network.webRTCNonProxiedUdpEnabled.set({ - value: !items.nonProxiedUDP, - scope: 'regular' - }); - }); - } - catch(e){ - status.textContent = 'Error.'; - status.style.color = "red"; - console.log("Error: " + e.message); - } - setTimeout(function(){ - status.textContent = ''; - }, 750); - }); - } + if(getMajorVerison() > 47){ + var policy = document.getElementById('policy').value; + chrome.storage.local.set({ + rtcIPHandling: policy + }, function(){ + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + status.style.color = "green"; + try{ + chrome.storage.local.get('rtcIPHandling', function(items){ + chrome.privacy.network.webRTCIPHandlingPolicy.set({ + value: items.rtcIPHandling + }); + }); + } + catch(e){ + status.textContent = 'Error.'; + status.style.color = "red"; + console.log("Error: " + e.message); + } + setTimeout(function(){ + status.textContent = ''; + }, 750); + }); + } + else if(getMajorVerison() > 41 && getMajorVerison() < 47){ + var rtcMultipleRoutes = document.getElementById('multipleroutes').checked; + chrome.storage.local.set({ + rtcMultipleRoutes: rtcMultipleRoutes + }, function(){ + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + status.style.color = "green"; + try{ + chrome.storage.local.get('rtcMultipleRoutes', function(items){ + chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ + value: !items.rtcMultipleRoutes, + scope: 'regular' + }); + }); + } + catch(e){ + status.textContent = 'Error.'; + status.style.color = "red"; + console.log("Error: " + e.message); + } + setTimeout(function(){ + status.textContent = ''; + }, 750); + }); + } + else if(getMajorVerison() == 47){ + var nonProxiedUDP = document.getElementById('proxy').checked; + var rtcMultipleRoutes = document.getElementById('multipleroutes').checked; + chrome.storage.local.set({ + nonProxiedUDP: nonProxiedUDP, + rtcMultipleRoutes: rtcMultipleRoutes + }, function(){ + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + status.style.color = "green"; + try{ + chrome.storage.local.get(null, function(items){ + chrome.privacy.network.webRTCMultipleRoutesEnabled.set({ + value: !items.rtcMultipleRoutes, + scope: 'regular' + }); + chrome.privacy.network.webRTCNonProxiedUdpEnabled.set({ + value: !items.nonProxiedUDP, + scope: 'regular' + }); + }); + } + catch(e){ + status.textContent = 'Error.'; + status.style.color = "red"; + console.log("Error: " + e.message); + } + setTimeout(function(){ + status.textContent = ''; + }, 750); + }); + } } /* Function to restore options. */ function restoreOptions(){ - if(getMajorVerison() > 47){ - chrome.storage.local.get({ - rtcIPHandling: 'default_public_interface_only' - }, function(items){ - document.getElementById('policy').value = items.rtcIPHandling; - }); - } - else if(getMajorVerison() > 41 && getMajorVerison() < 47){ - chrome.storage.local.get({ - rtcMultipleRoutes: true - }, function(items){ - document.getElementById('multipleroutes').checked = items.rtcMultipleRoutes; - }); - } - else if(getMajorVerison() == 47){ - chrome.storage.local.get({ - nonProxiedUDP: false, - rtcMultipleRoutes: true - }, function(items){ - document.getElementById('proxy').checked = items.nonProxiedUDP; - document.getElementById('multipleroutes').checked = items.rtcMultipleRoutes; - }); - } + if(getMajorVerison() > 47){ + chrome.storage.local.get({ + rtcIPHandling: 'default_public_interface_only' + }, function(items){ + document.getElementById('policy').value = items.rtcIPHandling; + }); + } + else if(getMajorVerison() > 41 && getMajorVerison() < 47){ + chrome.storage.local.get({ + rtcMultipleRoutes: true + }, function(items){ + document.getElementById('multipleroutes').checked = items.rtcMultipleRoutes; + }); + } + else if(getMajorVerison() == 47){ + chrome.storage.local.get({ + nonProxiedUDP: false, + rtcMultipleRoutes: true + }, function(items){ + document.getElementById('proxy').checked = items.nonProxiedUDP; + document.getElementById('multipleroutes').checked = items.rtcMultipleRoutes; + }); + } } /* Event listeners. */ document.addEventListener('DOMContentLoaded', displayContent); document.addEventListener('DOMContentLoaded', restoreOptions); document.getElementById('save').addEventListener('click', saveOptions); +document.getElementById('policy').addEventListener('change', saveOptions); +document.getElementById('proxy').addEventListener('change', saveOptions); +document.getElementById('multipleroutes').addEventListener('change', saveOptions); diff --git a/manifest.json b/manifest.json index 98db8f2..5d87120 100644 --- a/manifest.json +++ b/manifest.json @@ -1,23 +1,23 @@ { - "manifest_version": 2, - "name": "WebRTC Leak Prevent", - "version": "1.0.12", - "description": "Prevent WebRTC leaks using the official API.", - "icons": { - "128": "/img/icon128.png" - }, - "browser_action": { - "name": "Open options." - }, - "options_ui": { - "page": "/html/options.html", - "chrome_style": true, - "open_in_tab": false - }, - "minimum_chrome_version": "42", - "permissions": ["privacy", "storage"], - "background": { - "scripts": ["/js/background.js"], - "persistent": false - } + "manifest_version": 2, + "name": "WebRTC Leak Prevent", + "version": "1.0.13", + "description": "Prevent WebRTC leaks using the official API.", + "icons": { + "128": "/img/icon128.png" + }, + "browser_action": { + "name": "Open options." + }, + "options_ui": { + "page": "/html/options.html", + "chrome_style": true, + "open_in_tab": false + }, + "minimum_chrome_version": "42", + "permissions": ["privacy", "storage"], + "background": { + "scripts": ["/js/background.js"], + "persistent": false + } }