Fixed issues with tab initialization

This commit is contained in:
z0ccc 2022-06-22 23:10:34 -04:00
parent 588389fc75
commit 71d314ce65
6 changed files with 107 additions and 94 deletions

View file

@ -1,100 +1,24 @@
import attachDebugger from '../../utils/attachDebugger'
import userAgents from '../../utils/userAgents' import userAgents from '../../utils/userAgents'
const attachTab = (tabId) => { chrome.tabs.onCreated.addListener((tab) => {
chrome.storage.sync.get( attachDebugger(tab.id)
[ })
'ipData',
'timezone',
'timezoneMatchIP',
'lat',
'latitudeMatchIP',
'lon',
'longitudeMatchIP',
'locale',
'localeMatchIP',
'userAgent',
],
(result) => {
if (
result.timezone ||
result.lat ||
result.lon ||
result.locale ||
result.userAgent
) {
chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
if (!chrome.runtime.lastError) {
if (result.timezone) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setTimezoneOverride',
{
timezoneId: result.timezone,
},
() => {
if (
chrome.runtime.lastError &&
chrome.runtime.lastError.message.includes(
'Timezone override is already in effect'
)
) {
chrome.debugger.detach({ tabId })
attachTab(tabId)
}
}
)
}
if (result.locale) { chrome.tabs.onActivated.addListener((tab) => {
chrome.debugger.sendCommand( chrome.debugger.getTargets((tabs) => {
{ tabId: tabId }, const currentTab = tabs.find((obj) => obj.tabId === tab.tabId)
'Emulation.setLocaleOverride', if (!currentTab.attached) {
{ attachDebugger(tab.tabId)
locale: result.locale,
}
)
}
if (result.lat || result.lon) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
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(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent: result.userAgent,
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
)
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
}
})
}
} }
) })
} })
chrome.tabs.onUpdated.addListener((tabId, change, tab) => { chrome.tabs.onUpdated.addListener((tabId) => {
chrome.debugger.getTargets((tabs) => { chrome.debugger.getTargets((tabs) => {
const currentTab = tabs.find((obj) => obj.tabId === tabId) const currentTab = tabs.find((obj) => obj.tabId === tabId)
if (!currentTab.attached) { if (!currentTab.attached) {
attachTab(tabId) attachDebugger(tabId)
} }
}) })
}) })
@ -103,7 +27,6 @@ chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'userAgentAlarm') { if (alarm.name === 'userAgentAlarm') {
chrome.storage.sync.get(['randomUA'], (result) => { chrome.storage.sync.get(['randomUA'], (result) => {
if (result.randomUA) { if (result.randomUA) {
console.log('userAgentAlarm')
const randomUserAgent = const randomUserAgent =
userAgents[Math.floor(Math.random() * userAgents.length)] userAgents[Math.floor(Math.random() * userAgents.length)]
chrome.storage.sync.set({ chrome.storage.sync.set({

View file

@ -23,7 +23,7 @@ const Navbar = () => (
alt="Vytal logo" alt="Vytal logo"
/> />
<a <a
href="https://vytal.io/scan.html" href="https://vytal.io"
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
style={{ style={{

View file

@ -73,7 +73,7 @@ const Popup = () => {
fontSize: '10px', fontSize: '10px',
}} }}
> >
Tabs need to be initialized for full protection. Current tabs won't be fully spoofed until after first or second reload.
</div> </div>
</div> </div>
</div> </div>

View file

@ -13,7 +13,7 @@ body {
background-color: var(--background); background-color: var(--background);
font-size: 13px; font-size: 13px;
line-height: 22px; line-height: 22px;
width: 315px; width: 325px;
margin: 0; margin: 0;
font-family: 'Segoe UI', Tahoma, sans-serif; font-family: 'Segoe UI', Tahoma, sans-serif;
} }

View file

@ -0,0 +1,90 @@
const attachDebugger = (tabId) => {
chrome.storage.sync.get(
[
'ipData',
'timezone',
'timezoneMatchIP',
'lat',
'latitudeMatchIP',
'lon',
'longitudeMatchIP',
'locale',
'localeMatchIP',
'userAgent',
],
(result) => {
if (
result.timezone ||
result.lat ||
result.lon ||
result.locale ||
result.userAgent
) {
chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
if (!chrome.runtime.lastError) {
if (result.timezone) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setTimezoneOverride',
{
timezoneId: result.timezone,
},
() => {
if (
chrome.runtime.lastError &&
chrome.runtime.lastError.message.includes(
'Timezone override is already in effect'
)
) {
chrome.debugger.detach({ tabId })
}
}
)
}
if (result.locale) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setLocaleOverride',
{
locale: result.locale,
}
)
}
if (result.lat || result.lon) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
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(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent: result.userAgent,
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
)
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
}
})
}
}
)
}
export default attachDebugger

View file

@ -1,4 +1,4 @@
const detachDebugger = () => { const detachDebugger = (attach) => {
chrome.debugger.getTargets((tabs) => { chrome.debugger.getTargets((tabs) => {
for (const tab in tabs) { for (const tab in tabs) {
if (tabs[tab].attached && tabs[tab].tabId) { if (tabs[tab].attached && tabs[tab].tabId) {