use custom data for debugger

This commit is contained in:
z0ccc 2022-04-15 23:53:21 -04:00
parent d461af86e8
commit fbaac625ed
2 changed files with 68 additions and 45 deletions

View file

@ -1,58 +1,82 @@
import countryLocales from './countryLocales'
const attachTab = (tabId, ipData) => {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
if (!chrome.runtime.lastError) {
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.clearGeolocationOverride'
// )
chrome.storage.sync.get(
[
'ipData',
'timezone',
'timezoneMatchIP',
'lat',
'latitudeMatchIP',
'lon',
'longitudeMatchIP',
],
(result) => {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
if (!chrome.runtime.lastError) {
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.clearGeolocationOverride'
// )
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.clearIdleOverride'
// )
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.clearIdleOverride'
// )
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setTimezoneOverride',
{ timezoneId: ipData.timezone }
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setTimezoneOverride',
{
timezoneId: result.timezoneMatchIP
? result.ipData.timezone
: result.timezone,
}
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setLocaleOverride',
{ locale: countryLocales[ipData.countryCode].locale }
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setLocaleOverride',
{ locale: countryLocales[result.ipData.countryCode].locale }
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude: ipData.lat,
longitude: ipData.lon,
accuracy: 1,
const latitude = result.latMatchIP
? result.ipData.lat
: parseFloat(result.lat)
const longitude = result.lonMatchIP
? result.ipData.lon
: parseFloat(result.lon)
console.log(latitude, longitude)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude,
longitude,
accuracy: 1,
}
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
)
}
)
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
)
})
}
})
)
}
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
chrome.storage.sync.get(['ipData'], (result) => {
attachTab(tabId, result.ipData)
})
attachTab(tabId)
})
// const attachTabs = (ipData) => {

View file

@ -23,7 +23,7 @@ const DebugSettings = ({ type, ip }) => {
chrome.storage.sync.get([type, matchIPStorage], (result) => {
console.log(1, result)
// result[matchIPStorage] && setMatchIP(result[matchIPStorage])
setMatchIP(result[matchIPStorage])
if (result[matchIPStorage]) {
setValue(ip[type])
@ -50,7 +50,6 @@ const DebugSettings = ({ type, ip }) => {
}
const changeTextValue = (e) => {
console.log(e.target.value)
chrome.storage.sync.set({ [type]: e.target.value })
setValue(e.target.value)
if (matchIP) {