Webrtc policy handling

This commit is contained in:
z0ccc 2022-09-29 00:08:22 -04:00
parent 340e2f2f0f
commit 926ae242c6
7 changed files with 94 additions and 39 deletions

View file

@ -39,8 +39,8 @@ const LocationInput = ({
chrome.storage.sync.set({ [type]: ipTypeValue })
}
} else if (configuration === 'custom') {
chrome.storage.sync.get([type], (result) => {
result[type] && setValue(result[type])
chrome.storage.sync.get([type], (storage) => {
storage[type] && setValue(storage[type])
})
} else if (configuration !== 'default') {
setValue(configurations[configuration][type])

View file

@ -14,10 +14,10 @@ const LocationPage = ({ tab }: LocationPageProps) => {
const [configuration, setConfiguration] = useState('default')
useEffect(() => {
chrome.storage.sync.get(['configuration', 'ipData'], (result) => {
result.configuration && setConfiguration(result.configuration)
if (result.ipData) {
setIP(result.ipData)
chrome.storage.sync.get(['configuration', 'ipData'], (storage) => {
storage.configuration && setConfiguration(storage.configuration)
if (storage.ipData) {
setIP(storage.ipData)
} else {
Promise.resolve(getIP()).then((ipData) => setIP(ipData))
}

View file

@ -2,12 +2,14 @@ import { Label, Checkbox } from 'theme-ui'
interface LocationPageProps {
title: string
onChange?: () => void
checked?: boolean
}
const SettingsCheckBox = ({ title }: LocationPageProps) => {
const SettingsCheckBox = ({ title, onChange, checked }: LocationPageProps) => {
return (
<Label sx={{ mb: '8px' }}>
<Checkbox defaultChecked={true} />
<Checkbox onChange={onChange} checked={checked} />
{title}
</Label>
)

View file

@ -1,5 +1,6 @@
import { useState, useEffect } from 'react'
import { Box, Label, Checkbox, Select } from 'theme-ui'
import { Box, Label, Select } from 'theme-ui'
import setWebRtcPolicy from '../../utils/setWebRtcPolicy'
import SettingsCheckBox from './SettingsCheckBox'
interface LocationPageProps {
@ -7,9 +8,13 @@ interface LocationPageProps {
}
const SettingsPage = ({ tab }: LocationPageProps) => {
const [ip, setIP] = useState(null)
const [isWebRtcDisabled, setIsWebRtcDisabled] = useState(false)
useEffect(() => {}, [])
useEffect(() => {
chrome.storage.sync.get(['isWebRtcDisabled'], (storage) => {
storage.isWebRtcDisabled && setIsWebRtcDisabled(storage.isWebRtcDisabled)
})
}, [])
return (
<Box
@ -18,17 +23,31 @@ const SettingsPage = ({ tab }: LocationPageProps) => {
}}
>
<Box sx={{ fontSize: '20px', mb: '12px' }}>Settings</Box>
<SettingsCheckBox title={'Block WebRTC'} />
<SettingsCheckBox
title={'Block WebRTC'}
onChange={() => {
setWebRtcPolicy()
setIsWebRtcDisabled(!isWebRtcDisabled)
}}
checked={isWebRtcDisabled}
/>
<SettingsCheckBox title={'Block Address Autofill'} />
<SettingsCheckBox title={'Dark Mode'} />
<Label htmlFor="configuration">Language</Label>
<Select name="Language" id="Language">
<option>Arabic</option>
<option>Bengali</option>
<option>English</option>
<option>French</option>
<option>Chinese</option>
<option>Hindi</option>
<option>Mandarin Chinese</option>
<option>Persian</option>
<option>Portuguese</option>
<option>Russian</option>
<option>Farsi</option>
<option>Spanish</option>
<option>Turkish</option>
<option>Ukrainian</option>
<option>Urdu</option>
{/* {Object.keys(configurations).map((key) => (
<option value={key} key={key}>
{configurations[key].name}

View file

@ -16,11 +16,11 @@ const UserAgentPage = ({ tab }: UserAgentPageProps) => {
useEffect(() => {
chrome.storage.sync.get(
['type', 'operatingSystem', 'browser', 'userAgent'],
(result) => {
result.type && setType(result.type)
result.operatingSystem && setOperatingSystem(result.operatingSystem)
result.browser && setBrowser(result.browser)
result.userAgent && setUserAgent(result.userAgent)
(storage) => {
storage.type && setType(storage.type)
storage.operatingSystem && setOperatingSystem(storage.operatingSystem)
storage.browser && setBrowser(storage.browser)
storage.userAgent && setUserAgent(storage.userAgent)
}
)
}, [])

View file

@ -12,13 +12,13 @@ const attachDebugger = (tabId: number) => {
'localeMatchIP',
'userAgent',
],
(result) => {
(storage) => {
if (
result.timezone ||
result.lat ||
result.lon ||
result.locale ||
result.userAgent
storage.timezone ||
storage.lat ||
storage.lon ||
storage.locale ||
storage.userAgent
) {
chrome.debugger.attach({ tabId: tabId }, '1.3', () => {
if (!chrome.runtime.lastError) {
@ -31,12 +31,12 @@ const attachDebugger = (tabId: number) => {
// }
// )
if (result.timezone) {
if (storage.timezone) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setTimezoneOverride',
{
timezoneId: result.timezone,
timezoneId: storage.timezone,
},
() => {
if (
@ -51,38 +51,38 @@ const attachDebugger = (tabId: number) => {
)
}
if (result.locale) {
if (storage.locale) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setLocaleOverride',
{
locale: result.locale,
locale: storage.locale,
}
)
}
if (result.lat || result.lon) {
if (storage.lat || storage.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,
latitude: storage.lat
? parseFloat(storage.lat)
: storage.ipData.lat,
longitude: storage.lon
? parseFloat(storage.lon)
: storage.ipData.lon,
accuracy: 1,
}
)
}
if (result.userAgent) {
if (storage.userAgent) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent: result.userAgent,
userAgent: storage.userAgent,
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }

View file

@ -0,0 +1,34 @@
const setWebRtcPolicy = () => {
chrome.storage.sync.get(['isWebRtcDisabled'], (storage) => {
const value = storage.isWebRtcDisabled
? 'default'
: 'disable_non_proxied_udp'
chrome.privacy.network.webRTCIPHandlingPolicy.clear({}, () => {
chrome.privacy.network.webRTCIPHandlingPolicy.set(
{
value,
},
() => {
chrome.storage.sync.set({
isWebRtcDisabled: !storage.isWebRtcDisabled,
})
// chrome.privacy.network.webRTCIPHandlingPolicy.get({}, (s) => {
// // let path = 'data/icons/'
// // let title = 'WebRTC access is allowed'
// if (s.value !== value) {
// // path += 'red/'
// // title =
// console.log('WebRTC access cannot be changed. It is controlled by another extension')
// } else if (prefs.enabled === false) {
// path += 'disabled/'
// title = 'WebRTC access is blocked'
// }
// })
}
)
})
})
}
export default setWebRtcPolicy