From 9dde601943e73a5a54e57c6404cef3d6bd04da7d Mon Sep 17 00:00:00 2001 From: Ray Lothian Date: Mon, 14 Nov 2022 03:09:45 -0500 Subject: [PATCH] new fix for #160 --- v2/firefox/common.js | 61 ++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/v2/firefox/common.js b/v2/firefox/common.js index 4549159..53ebc89 100644 --- a/v2/firefox/common.js +++ b/v2/firefox/common.js @@ -536,43 +536,38 @@ const onBeforeSendHeaders = d => { } // https://github.com/ray-lothian/UserAgent-Switcher/issues/160 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; - } - } - else { - requestHeaders[i] = null; - } + requestHeaders[i] = null; } } + if (o.userAgentDataBuilder) { + let platform = o.userAgentDataBuilder.p?.os?.name || 'Windows'; + if (platform.toLowerCase().includes('mac')) { + platform = 'macOS'; + } + + const version = o.userAgentDataBuilder.p?.browser?.major || 107; + let name = o.userAgentDataBuilder.p?.browser?.name || 'Google Chrome'; + if (name === 'Chrome') { + name = 'Google Chrome'; + } + else if (name.includes('debian')) { + platform = 'Linux'; + } + + requestHeaders.push({ + name: 'sec-ch-ua-platform', + value: '"' + platform + '"' + }, { + name: 'sec-ch-ua', + value: `"${name}";v="${version}", "Chromium";v="${version}", "Not=A?Brand";v="24"` + }, { + name: 'sec-ch-ua-mobile', + value: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(o.userAgent) ? '?1' : '?0' + }); + } } return { - requestHeaders: requestHeaders.filter(a => a) + requestHeaders: requestHeaders.filter(o => o) }; };