new fix for #160
This commit is contained in:
parent
8b68d5f2dd
commit
d05f980652
1 changed files with 39 additions and 4 deletions
|
@ -266,7 +266,7 @@ const ua = {
|
||||||
o.productSub = '20030107';
|
o.productSub = '20030107';
|
||||||
|
|
||||||
if (prefs.userAgentData && p.browser && p.browser.major) {
|
if (prefs.userAgentData && p.browser && p.browser.major) {
|
||||||
if (['Opera', 'Chrome', 'Edge', 'Vivaldi'].includes(p.browser.name)) {
|
if (['Opera', 'Chrome', 'Edge'].includes(p.browser.name)) {
|
||||||
o.userAgentDataBuilder = {p, ua: s};
|
o.userAgentDataBuilder = {p, ua: s};
|
||||||
delete o.userAgentData;
|
delete o.userAgentData;
|
||||||
}
|
}
|
||||||
|
@ -536,9 +536,40 @@ const onBeforeSendHeaders = d => {
|
||||||
}
|
}
|
||||||
// https://github.com/ray-lothian/UserAgent-Switcher/issues/160
|
// https://github.com/ray-lothian/UserAgent-Switcher/issues/160
|
||||||
else if (name.startsWith('sec-ch-')) {
|
else if (name.startsWith('sec-ch-')) {
|
||||||
|
if (o.userAgentDataBuilder) {
|
||||||
|
if (name === 'sec-ch-ua-platform') {
|
||||||
|
let platform = o.userAgentDataBuilder.p?.os?.name || 'Windows';
|
||||||
|
|
||||||
|
if (platform.toLowerCase().includes('mac')) {
|
||||||
|
platform = 'macOS';
|
||||||
|
}
|
||||||
|
else if (name.includes('debian')) {
|
||||||
|
platform = 'Linux';
|
||||||
|
}
|
||||||
|
|
||||||
|
requestHeaders[i].value = '"' + platform + '"';
|
||||||
|
}
|
||||||
|
else if (name === 'sec-ch-ua') {
|
||||||
|
const version = o.userAgentDataBuilder.p?.browser?.major || 107;
|
||||||
|
let name = o.userAgentDataBuilder.p?.browser?.name || 'Google Chrome';
|
||||||
|
if (name === 'Chrome') {
|
||||||
|
name = 'Google Chrome';
|
||||||
|
}
|
||||||
|
requestHeaders[i].value = `"${name}";v="${version}", "Chromium";v="${version}", "Not=A?Brand";v="24"`;
|
||||||
|
}
|
||||||
|
else if (name === 'sec-ch-ua-mobile') {
|
||||||
|
requestHeaders[i].value =
|
||||||
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(o.userAgent) ? '?1' : '?0';
|
||||||
|
}
|
||||||
|
else {
|
||||||
requestHeaders[i] = null;
|
requestHeaders[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
requestHeaders[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
requestHeaders: requestHeaders.filter(a => a)
|
requestHeaders: requestHeaders.filter(a => a)
|
||||||
|
@ -567,7 +598,7 @@ const onCommitted = d => {
|
||||||
const o = JSON.parse(decodeURIComponent(escape(atob('${s}'))));
|
const o = JSON.parse(decodeURIComponent(escape(atob('${s}'))));
|
||||||
|
|
||||||
if (o.userAgentDataBuilder) {
|
if (o.userAgentDataBuilder) {
|
||||||
navigator.userAgentData = new class NavigatorUAData {
|
const v = new class NavigatorUAData {
|
||||||
#p;
|
#p;
|
||||||
|
|
||||||
constructor({p, ua}) {
|
constructor({p, ua}) {
|
||||||
|
@ -587,7 +618,7 @@ const onCommitted = d => {
|
||||||
version: '24'
|
version: '24'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
this.mobile = /Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
this.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Platform
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Platform
|
||||||
this.platform = 'Unknown';
|
this.platform = 'Unknown';
|
||||||
|
@ -639,6 +670,10 @@ const onCommitted = d => {
|
||||||
return Promise.resolve(r);
|
return Promise.resolve(r);
|
||||||
}
|
}
|
||||||
}(o.userAgentDataBuilder);
|
}(o.userAgentDataBuilder);
|
||||||
|
|
||||||
|
navigator.__defineGetter__('userAgentData', () => {
|
||||||
|
return v;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
delete o.userAgentDataBuilder;
|
delete o.userAgentDataBuilder;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue