From 8b93a731b0ec8ef6419455924eca2a8df80f284d Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Wed, 13 Mar 2019 09:27:20 +0100 Subject: [PATCH] possible fix for #25 --- extension/common.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/extension/common.js b/extension/common.js index ac22fc7..3201072 100644 --- a/extension/common.js +++ b/extension/common.js @@ -35,21 +35,21 @@ chrome.storage.local.get(prefs, ps => { contexts: ['browser_action'], type: 'radio', checked: prefs.mode === 'blacklist' - }); + }, () => chrome.runtime.lastError); chrome.contextMenus.create({ id: 'whitelist', title: 'Switch to "white-list" mode', contexts: ['browser_action'], type: 'radio', checked: prefs.mode === 'whitelist' - }); + }, () => chrome.runtime.lastError); chrome.contextMenus.create({ id: 'custom', title: 'Switch to "custom" mode', contexts: ['browser_action'], type: 'radio', checked: prefs.mode === 'custom' - }); + }, () => chrome.runtime.lastError); }); chrome.storage.onChanged.addListener(ps => { Object.keys(ps).forEach(key => prefs[key] = ps[key].newValue); @@ -264,17 +264,18 @@ var onCommitted = ({frameId, url, tabId}) => { if (o.userAgent === 'empty') { userAgent = appVersion = platform = vendor = ''; } + const fix = s => s.replace(/`/g, String.fromCharCode(0)); chrome.tabs.executeScript(tabId, { runAt: 'document_start', frameId, code: `{ const script = document.createElement('script'); script.textContent = \`{ - navigator.__defineGetter__('userAgent', () => '${userAgent}'); - navigator.__defineGetter__('appVersion', () => '${appVersion}'); - navigator.__defineGetter__('platform', () => '${platform}'); - navigator.__defineGetter__('vendor', () => '${vendor}'); - }\`; + navigator.__defineGetter__('userAgent', () => '${fix(userAgent)}'); + navigator.__defineGetter__('appVersion', () => '${fix(appVersion)}'); + navigator.__defineGetter__('platform', () => '${fix(platform)}'); + navigator.__defineGetter__('vendor', () => '${fix(vendor)}'); + }\`.replace(new RegExp(String.fromCharCode(0), 'g'), '\`'); document.documentElement.appendChild(script); script.remove(); }`