From bec416ae74ca74dc5a078d9c8b8d73ae50d4f052 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Wed, 20 Apr 2022 21:44:42 -0400 Subject: [PATCH] Added useragent masking --- src/pages/Background/index.js | 40 +++++++++++++++++++------- src/pages/Popup/DebugSettings.js | 10 ------- src/pages/Popup/LocaleSettings.js | 20 ++++--------- src/pages/Popup/Popup.jsx | 2 ++ src/pages/Popup/UserAgentSettings.js | 43 ++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 src/pages/Popup/UserAgentSettings.js diff --git a/src/pages/Background/index.js b/src/pages/Background/index.js index 51833c6..7c41990 100644 --- a/src/pages/Background/index.js +++ b/src/pages/Background/index.js @@ -12,6 +12,7 @@ const attachTab = (tabId, ipData) => { 'longitudeMatchIP', 'locale', 'localeMatchIP', + 'userAgent', ], (result) => { 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( { tabId: tabId }, 'Emulation.setLocaleOverride', @@ -53,6 +65,12 @@ const attachTab = (tabId, ipData) => { ? result.ipData.lon : parseFloat(result.lon) + console.log( + result.latMatchIP, + result.ipData.lat, + parseFloat(result.lat) + ) + chrome.debugger.sendCommand( { tabId: tabId }, 'Emulation.setGeolocationOverride', @@ -63,16 +81,18 @@ const attachTab = (tabId, ipData) => { } ) - 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" } - ) + 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', + } } }) } diff --git a/src/pages/Popup/DebugSettings.js b/src/pages/Popup/DebugSettings.js index 6248598..ed409d8 100644 --- a/src/pages/Popup/DebugSettings.js +++ b/src/pages/Popup/DebugSettings.js @@ -1,15 +1,5 @@ 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 [value, setValue] = useState('') const [matchIP, setMatchIP] = useState(false) diff --git a/src/pages/Popup/LocaleSettings.js b/src/pages/Popup/LocaleSettings.js index 05bef9a..d467ee3 100644 --- a/src/pages/Popup/LocaleSettings.js +++ b/src/pages/Popup/LocaleSettings.js @@ -1,16 +1,6 @@ import React, { useState, useEffect, useRef } from 'react' 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 [value, setValue] = useState('') const [matchIP, setMatchIP] = useState(false) @@ -20,10 +10,10 @@ const LocaleSettings = ({ ip }) => { if (ip) { locale.current = countryLocales[ip.countryCode].locale - chrome.storage.sync.get(['locale', 'localeMathIP'], (result) => { - result.localeMathIP && setMatchIP(result.localeMathIP) + chrome.storage.sync.get(['locale', 'localeMatchIP'], (result) => { + result.localeMatchIP && setMatchIP(result.localeMatchIP) - if (result.localeMathIP) { + if (result.localeMatchIP) { setValue(locale.current) chrome.storage.sync.set({ locale: locale.current }) } else if (result.locale) { @@ -37,13 +27,13 @@ const LocaleSettings = ({ ip }) => { chrome.storage.sync.set({ locale: e.target.value }) setValue(e.target.value) if (matchIP) { - chrome.storage.sync.set({ localeMathIP: !matchIP }) + chrome.storage.sync.set({ localeMatchIP: !matchIP }) setMatchIP(!matchIP) } } const toggleMatchIP = (e) => { - chrome.storage.sync.set({ localeMathIP: !matchIP }) + chrome.storage.sync.set({ localeMatchIP: !matchIP }) !matchIP && setValue(locale.current) setMatchIP(e.target.value) } diff --git a/src/pages/Popup/Popup.jsx b/src/pages/Popup/Popup.jsx index 8df153a..049eb54 100644 --- a/src/pages/Popup/Popup.jsx +++ b/src/pages/Popup/Popup.jsx @@ -3,6 +3,7 @@ import Navbar from './Navbar' import IpSettings from './IpSettings' import DebugSettings from './DebugSettings' import LocaleSettings from './LocaleSettings' +import UserAgentSettings from './UserAgentSettings' const getIP = () => fetch('http://ip-api.com/json/') @@ -38,6 +39,7 @@ const Popup = () => { + ) diff --git a/src/pages/Popup/UserAgentSettings.js b/src/pages/Popup/UserAgentSettings.js new file mode 100644 index 0000000..ac6e801 --- /dev/null +++ b/src/pages/Popup/UserAgentSettings.js @@ -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 ( +
+ +
+ ) +} + +export default UserAgentSettings