Added useragent masking

This commit is contained in:
z0ccc 2022-04-20 21:44:42 -04:00
parent 2117156138
commit bec416ae74
5 changed files with 80 additions and 35 deletions

View file

@ -12,6 +12,7 @@ const attachTab = (tabId, ipData) => {
'longitudeMatchIP', 'longitudeMatchIP',
'locale', 'locale',
'localeMatchIP', 'localeMatchIP',
'userAgent',
], ],
(result) => { (result) => {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () { chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
@ -36,6 +37,17 @@ 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
)
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
'Emulation.setLocaleOverride', 'Emulation.setLocaleOverride',
@ -53,6 +65,12 @@ const attachTab = (tabId, ipData) => {
? result.ipData.lon ? result.ipData.lon
: parseFloat(result.lon) : parseFloat(result.lon)
console.log(
result.latMatchIP,
result.ipData.lat,
parseFloat(result.lat)
)
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
'Emulation.setGeolocationOverride', 'Emulation.setGeolocationOverride',
@ -63,16 +81,18 @@ const attachTab = (tabId, ipData) => {
} }
) )
chrome.debugger.sendCommand( if (result.userAgent) {
{ tabId: tabId }, chrome.debugger.sendCommand(
'Emulation.setUserAgentOverride', { 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', userAgent: result.userAgent,
} }
// { acceptLanguage: "en-CA" }, // { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" } // { platform: "WebTV OS" }
) )
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
} }
}) })
} }

View file

@ -1,15 +1,5 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } 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 })
}
}
})
}
const DebugSettings = ({ type, title, ip }) => { const DebugSettings = ({ type, title, ip }) => {
const [value, setValue] = useState('') const [value, setValue] = useState('')
const [matchIP, setMatchIP] = useState(false) const [matchIP, setMatchIP] = useState(false)

View file

@ -1,16 +1,6 @@
import React, { useState, useEffect, useRef } from 'react' import React, { useState, useEffect, useRef } from 'react'
import countryLocales from '../../utils/countryLocales' import countryLocales from '../../utils/countryLocales'
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 })
}
}
})
}
const LocaleSettings = ({ ip }) => { const LocaleSettings = ({ ip }) => {
const [value, setValue] = useState('') const [value, setValue] = useState('')
const [matchIP, setMatchIP] = useState(false) const [matchIP, setMatchIP] = useState(false)
@ -20,10 +10,10 @@ const LocaleSettings = ({ ip }) => {
if (ip) { if (ip) {
locale.current = countryLocales[ip.countryCode].locale locale.current = countryLocales[ip.countryCode].locale
chrome.storage.sync.get(['locale', 'localeMathIP'], (result) => { chrome.storage.sync.get(['locale', 'localeMatchIP'], (result) => {
result.localeMathIP && setMatchIP(result.localeMathIP) result.localeMatchIP && setMatchIP(result.localeMatchIP)
if (result.localeMathIP) { if (result.localeMatchIP) {
setValue(locale.current) setValue(locale.current)
chrome.storage.sync.set({ locale: locale.current }) chrome.storage.sync.set({ locale: locale.current })
} else if (result.locale) { } else if (result.locale) {
@ -37,13 +27,13 @@ const LocaleSettings = ({ ip }) => {
chrome.storage.sync.set({ locale: e.target.value }) chrome.storage.sync.set({ locale: e.target.value })
setValue(e.target.value) setValue(e.target.value)
if (matchIP) { if (matchIP) {
chrome.storage.sync.set({ localeMathIP: !matchIP }) chrome.storage.sync.set({ localeMatchIP: !matchIP })
setMatchIP(!matchIP) setMatchIP(!matchIP)
} }
} }
const toggleMatchIP = (e) => { const toggleMatchIP = (e) => {
chrome.storage.sync.set({ localeMathIP: !matchIP }) chrome.storage.sync.set({ localeMatchIP: !matchIP })
!matchIP && setValue(locale.current) !matchIP && setValue(locale.current)
setMatchIP(e.target.value) setMatchIP(e.target.value)
} }

View file

@ -3,6 +3,7 @@ import Navbar from './Navbar'
import IpSettings from './IpSettings' import IpSettings from './IpSettings'
import DebugSettings from './DebugSettings' import DebugSettings from './DebugSettings'
import LocaleSettings from './LocaleSettings' import LocaleSettings from './LocaleSettings'
import UserAgentSettings from './UserAgentSettings'
const getIP = () => const getIP = () =>
fetch('http://ip-api.com/json/') fetch('http://ip-api.com/json/')
@ -38,6 +39,7 @@ const Popup = () => {
<DebugSettings type="lat" title="Latitude" ip={ip} /> <DebugSettings type="lat" title="Latitude" ip={ip} />
<DebugSettings type="lon" title="Longitude" ip={ip} /> <DebugSettings type="lon" title="Longitude" ip={ip} />
<LocaleSettings ip={ip} /> <LocaleSettings ip={ip} />
<UserAgentSettings ip={ip} type="lat" title="Latitude" />
</div> </div>
</div> </div>
) )

View file

@ -0,0 +1,43 @@
import React, { useState, useEffect } from 'react'
const UserAgentSettings = () => {
const [value, setUserAgent] = useState('')
useEffect(() => {
chrome.storage.sync.get(['userAgent'], (result) => {
if (result.userAgent) {
setUserAgent(result.userAgent)
}
})
}, [])
const changeTextValue = (e) => {
chrome.storage.sync.set({ userAgent: e.target.value })
setUserAgent(e.target.value)
}
return (
<div
style={{
display: 'flex',
justifyContent: 'space-between',
margin: '12px 0 0 0',
}}
>
<label>
<input
type="text"
value={value}
onChange={changeTextValue}
style={{
width: '218px',
margin: '0 5px 0 0',
}}
/>
User Agent
</label>
</div>
)
}
export default UserAgentSettings