new fix for #25

This commit is contained in:
Ray Lothian 2019-03-14 08:14:11 +01:00
parent abca844d5d
commit 31c12610f2

View file

@ -254,30 +254,31 @@ var onBeforeSendHeaders = ({tabId, url, requestHeaders, type}) => {
}; };
var onCommitted = ({frameId, url, tabId}) => { var onCommitted = ({frameId, url, tabId}) => {
console.log(url, cache[tabId] === true);
if (url && (url.startsWith('http') || url.startsWith('ftp')) || url === 'about:blank') { if (url && (url.startsWith('http') || url.startsWith('ftp')) || url === 'about:blank') {
if (cache[tabId] === true) { if (cache[tabId] === true) {
return; return;
} }
const o = cache[tabId] || ua.object(tabId); const o = cache[tabId] || ua.object(tabId);
console.log(o, url);
if (o.userAgent) { if (o.userAgent) {
let {userAgent, appVersion, platform, vendor} = o; let {userAgent, appVersion, platform, vendor} = o;
if (o.userAgent === 'empty') { if (o.userAgent === 'empty') {
userAgent = appVersion = platform = vendor = ''; userAgent = appVersion = platform = vendor = '';
} }
const fix = s => s.replace(/`/g, String.fromCharCode(0));
chrome.tabs.executeScript(tabId, { chrome.tabs.executeScript(tabId, {
runAt: 'document_start', runAt: 'document_start',
frameId, frameId,
code: `{ code: `{
const script = document.createElement('script'); const script = document.createElement('script');
script.textContent = \`{ script.textContent = \`{
navigator.__defineGetter__('userAgent', () => '${fix(userAgent)}'); const userAgent = "${encodeURIComponent(userAgent)}";
navigator.__defineGetter__('appVersion', () => '${fix(appVersion)}'); const appVersion = "${encodeURIComponent(appVersion)}";
navigator.__defineGetter__('platform', () => '${fix(platform)}'); const platform = "${encodeURIComponent(platform)}";
navigator.__defineGetter__('vendor', () => '${fix(vendor)}'); const vendor = "${encodeURIComponent(vendor)}";
}\`.replace(new RegExp(String.fromCharCode(0), 'g'), '\`'); navigator.__defineGetter__('userAgent', () => decodeURIComponent(userAgent));
navigator.__defineGetter__('appVersion', () => decodeURIComponent(appVersion));
navigator.__defineGetter__('platform', () => decodeURIComponent(platform));
navigator.__defineGetter__('vendor', () => decodeURIComponent(vendor));
}\`;
document.documentElement.appendChild(script); document.documentElement.appendChild(script);
script.remove(); script.remove();
}` }`