From cf406dac30c24af77a022ca66bf64c980710c520 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Thu, 5 May 2022 14:30:45 -0400 Subject: [PATCH] Fixed overriding timezone bug --- src/pages/Background/index.js | 12 ++++++------ src/pages/Popup/DebugSettings.js | 2 ++ src/pages/Popup/IpSettings.js | 11 +---------- src/utils/detachDebugger.js | 12 ++++++++++++ 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src/utils/detachDebugger.js diff --git a/src/pages/Background/index.js b/src/pages/Background/index.js index 2a6200c..81304b2 100644 --- a/src/pages/Background/index.js +++ b/src/pages/Background/index.js @@ -27,11 +27,6 @@ const attachTab = (tabId, ipData) => { // 'Emulation.clearGeolocationOverride' // ) - // chrome.debugger.sendCommand( - // { tabId: tabId }, - // 'Emulation.clearIdleOverride' - // ) - if (result.timezone) { chrome.debugger.sendCommand( { tabId: tabId }, @@ -88,7 +83,12 @@ const attachTab = (tabId, ipData) => { } chrome.tabs.onUpdated.addListener((tabId, change, tab) => { - attachTab(tabId) + chrome.debugger.getTargets((tabs) => { + const currentTab = tabs.find((obj) => obj.tabId === tabId) + if (!currentTab.attached) { + attachTab(tabId) + } + }) }) // const attachTabs = (ipData) => { diff --git a/src/pages/Popup/DebugSettings.js b/src/pages/Popup/DebugSettings.js index 3ea74fa..6059dca 100644 --- a/src/pages/Popup/DebugSettings.js +++ b/src/pages/Popup/DebugSettings.js @@ -1,4 +1,5 @@ import React, { useState, useEffect } from 'react' +import detachDebugger from '../../utils/detachDebugger' const DebugSettings = ({ type, title, ip }) => { const [value, setValue] = useState('') @@ -27,6 +28,7 @@ const DebugSettings = ({ type, title, ip }) => { chrome.storage.sync.set({ [matchIPStorage]: !matchIP }) setMatchIP(!matchIP) } + // detachDebugger() } const toggleMatchIP = (e) => { diff --git a/src/pages/Popup/IpSettings.js b/src/pages/Popup/IpSettings.js index 5084728..a0e4c45 100644 --- a/src/pages/Popup/IpSettings.js +++ b/src/pages/Popup/IpSettings.js @@ -1,14 +1,5 @@ import React from 'react' - -const detachDebugger = () => { - chrome.debugger.getTargets((tabs) => { - for (const tab in tabs) { - if (tabs[tab].attached && tabs[tab].tabId) { - chrome.debugger.detach({ tabId: tabs[tab].tabId }) - } - } - }) -} +import detachDebugger from '../../utils/detachDebugger' const getFlagEmoji = (countryCode) => { const codePoints = countryCode diff --git a/src/utils/detachDebugger.js b/src/utils/detachDebugger.js new file mode 100644 index 0000000..7d0dab2 --- /dev/null +++ b/src/utils/detachDebugger.js @@ -0,0 +1,12 @@ +const detachDebugger = () => { + chrome.debugger.getTargets((tabs) => { + console.log(tabs) + for (const tab in tabs) { + if (tabs[tab].attached && tabs[tab].tabId) { + chrome.debugger.detach({ tabId: tabs[tab].tabId }) + } + } + }) +} + +export default detachDebugger