supporting bot user-agents

This commit is contained in:
Ray Lothian 2020-08-04 12:16:03 +02:00
parent d0340982fc
commit bf16cb694a
13 changed files with 44 additions and 16 deletions

View file

@ -84,6 +84,7 @@ chrome.storage.local.get(prefs, ps => {
}, () => chrome.runtime.lastError);
});
chrome.storage.onChanged.addListener(ps => {
console.log(ps);
Object.keys(ps).forEach(key => prefs[key] = ps[key].newValue);
if (ps.ua || ps.mode) {
ua.update();
@ -156,7 +157,6 @@ const ua = {
}
});
}
return o;
},
object(tabId, windowId) {
@ -216,6 +216,7 @@ const ua = {
}
},
update(str = prefs.ua, windowId = 'global') {
console.log(str);
log('ua.update is called', str, windowId);
// clear caching
Object.keys(cache).forEach(key => delete cache[key]);
@ -356,7 +357,7 @@ const onBeforeSendHeaders = ({tabId, url, requestHeaders, type}) => {
}
const str = (cache[tabId] || ua.object(tabId)).userAgent;
if (str) {
for (let i = 0, name = requestHeaders[0].name; i < requestHeaders.length; i += 1, name = requestHeaders[i].name) {
for (let i = 0, name = requestHeaders[0].name; i < requestHeaders.length; i += 1, name = (requestHeaders[i] || {}).name) {
if (name === 'User-Agent' || name === 'user-agent') {
requestHeaders[i].value = str === 'empty' ? '' : str;
return {

View file

@ -83,9 +83,19 @@ function update(ua) {
for (const o of sort(list)) {
const clone = document.importNode(t.content, true);
const second = clone.querySelector('td:nth-child(2)');
second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' ');
if (o.browser.name && o.browser.version) {
second.title = second.textContent = o.browser.name + ' ' + (o.browser.version || ' ');
}
else {
second.title = second.textContent = '-';
}
const third = clone.querySelector('td:nth-child(3)');
third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' ');
if (o.os.name && o.os.version) {
third.title = third.textContent = o.os.name + ' ' + (o.os.version || ' ');
}
else {
third.title = third.textContent = '-';
}
const forth = clone.querySelector('td:nth-child(4)');
forth.title = forth.textContent = o.ua;
if (o.ua === ua) {
@ -218,7 +228,13 @@ document.addEventListener('click', ({target}) => {
msg('User-Agent is Set');
}
chrome.storage.local.set({
ua: value === navigator.userAgent ? '' : value
ua: '' // since we set from managed storage, the value might already be this one and hence onChanged is not being called
}, () => {
if (value !== navigator.userAgent) {
chrome.storage.local.set({
ua: value
});
}
});
}
else if (cmd === 'window') {