Only attach if options enabled

This commit is contained in:
z0ccc 2022-05-02 17:31:39 -04:00
parent ebf2e47b9c
commit 27e0e414f9

View file

@ -1,5 +1,3 @@
import countryLocales from '../../utils/countryLocales'
const attachTab = (tabId, ipData) => {
chrome.storage.sync.get(
[
@ -15,6 +13,13 @@ const attachTab = (tabId, ipData) => {
'userAgent',
],
(result) => {
if (
result.timezone ||
result.lat ||
result.lon ||
result.locale ||
result.userAgent
) {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
if (!chrome.runtime.lastError) {
// chrome.debugger.sendCommand(
@ -37,17 +42,6 @@ const attachTab = (tabId, ipData) => {
)
}
console.log(
result.localeMatchIP,
countryLocales[result.ipData.countryCode].locale,
result.locale
)
console.log(
result.localeMatchIP
? countryLocales[result.ipData.countryCode].locale
: result.locale
)
if (result.locale) {
chrome.debugger.sendCommand(
{ tabId: tabId },
@ -58,28 +52,21 @@ const attachTab = (tabId, ipData) => {
)
}
const latitude = result.latMatchIP
? result.ipData.lat
: parseFloat(result.lat)
const longitude = result.lonMatchIP
? result.ipData.lon
: parseFloat(result.lon)
console.log(
result.latMatchIP,
result.ipData.lat,
parseFloat(result.lat)
)
if (result.lat || result.lon) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude,
longitude,
latitude: result.lat
? parseFloat(result.lat)
: result.ipData.lat,
longitude: result.lon
? parseFloat(result.lon)
: result.ipData.lon,
accuracy: 1,
}
)
}
if (result.userAgent) {
chrome.debugger.sendCommand(
@ -96,6 +83,7 @@ const attachTab = (tabId, ipData) => {
}
})
}
}
)
}