Webrtc page
This commit is contained in:
parent
0b5c77baea
commit
15acdc0a38
13 changed files with 232 additions and 34 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
"@hot-loader/react-dom": "^17.0.2",
|
"@hot-loader/react-dom": "^17.0.2",
|
||||||
"@mdx-js/react": "^2.1.2",
|
"@mdx-js/react": "^2.1.2",
|
||||||
"@types/webpack-env": "^1.18.0",
|
"@types/webpack-env": "^1.18.0",
|
||||||
|
"@types/webrtc": "^0.0.33",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-feather": "^2.0.10",
|
"react-feather": "^2.0.10",
|
||||||
|
|
|
||||||
18
src/Popup/Components/CheckBox.tsx
Normal file
18
src/Popup/Components/CheckBox.tsx
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Label, Checkbox } from 'theme-ui'
|
||||||
|
|
||||||
|
interface LocationPageProps {
|
||||||
|
title: string
|
||||||
|
onChange?: () => void
|
||||||
|
checked?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const CheckBox = ({ title, onChange, checked }: LocationPageProps) => {
|
||||||
|
return (
|
||||||
|
<Label sx={{ mb: '8px' }}>
|
||||||
|
<Checkbox onChange={onChange} checked={checked} />
|
||||||
|
{title}
|
||||||
|
</Label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CheckBox
|
||||||
36
src/Popup/Pages/AddressAutofillPage/index.tsx
Normal file
36
src/Popup/Pages/AddressAutofillPage/index.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { Box } from 'theme-ui'
|
||||||
|
|
||||||
|
import getIP from '../../../utils/getIP'
|
||||||
|
|
||||||
|
interface LocationPageProps {
|
||||||
|
tab: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const AddressAutofillPage = ({ tab }: LocationPageProps) => {
|
||||||
|
const [ip, setIP] = useState(null)
|
||||||
|
const [configuration, setConfiguration] = useState('default')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: tab === 'addressAutofill' ? 'block' : 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ fontSize: '20px', mb: '8px' }}>Address Autofill</Box>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AddressAutofillPage
|
||||||
|
|
@ -30,7 +30,7 @@ const LocationPage = ({ tab }: LocationPageProps) => {
|
||||||
display: tab === 'location' ? 'block' : 'none',
|
display: tab === 'location' ? 'block' : 'none',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box sx={{ fontSize: '20px', mb: '8px' }}>Location</Box>
|
<Box sx={{ fontSize: '20px', mb: '8px' }}>Location Data</Box>
|
||||||
<ConfigurationSelect
|
<ConfigurationSelect
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { Box, Label, Select } from 'theme-ui'
|
import { Box, Label, Select } from 'theme-ui'
|
||||||
import setWebRtcPolicy from '../../../utils/setWebRtcPolicy'
|
import setWebRtcPolicy from '../WebRtcPage/handleWebRtcPolicy'
|
||||||
import SettingsCheckBox from './SettingsCheckBox'
|
import SettingsCheckBox from './SettingsCheckBox'
|
||||||
|
|
||||||
interface LocationPageProps {
|
interface LocationPageProps {
|
||||||
|
|
@ -33,11 +33,11 @@ const SettingsPage = ({ tab }: LocationPageProps) => {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box sx={{ fontSize: '20px', mb: '12px' }}>Settings</Box>
|
<Box sx={{ fontSize: '20px', mb: '12px' }}>Settings</Box>
|
||||||
<SettingsCheckBox
|
{/* <SettingsCheckBox
|
||||||
title={'Disable WebRTC'}
|
title={'Disable WebRTC'}
|
||||||
onChange={setWebRtcPolicy}
|
onChange={setWebRtcPolicy}
|
||||||
checked={isWebRtcDisabled}
|
checked={isWebRtcDisabled}
|
||||||
/>
|
/> */}
|
||||||
<SettingsCheckBox title={'Disable Address Autofill'} />
|
<SettingsCheckBox title={'Disable Address Autofill'} />
|
||||||
<SettingsCheckBox title={'Dark Mode'} />
|
<SettingsCheckBox title={'Dark Mode'} />
|
||||||
<Label htmlFor="configuration">Language</Label>
|
<Label htmlFor="configuration">Language</Label>
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ const UserAgentPage = ({ tab }: UserAgentPageProps) => {
|
||||||
display: tab === 'useragent' ? 'block' : 'none',
|
display: tab === 'useragent' ? 'block' : 'none',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box sx={{ fontSize: '20px', mb: '12px' }}>User Agent</Box>
|
<Box sx={{ fontSize: '20px', mb: '12px' }}>Other Options</Box>
|
||||||
<Flex
|
<Flex
|
||||||
sx={{
|
sx={{
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
|
|
|
||||||
73
src/Popup/Pages/WebRtcPage/getWebRTCData.ts
Normal file
73
src/Popup/Pages/WebRtcPage/getWebRTCData.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
const getWebRTC = (setWebRtcIp: any) => {
|
||||||
|
// if (navigator.getUserMedia) {
|
||||||
|
const ipRegex =
|
||||||
|
/([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
|
||||||
|
|
||||||
|
// compatibility for firefox and chrome
|
||||||
|
let RTCPeerConnection = window.RTCPeerConnection
|
||||||
|
|
||||||
|
// minimal requirements for data connection
|
||||||
|
const mediaConstraints = {
|
||||||
|
optional: [{ RtpDataChannels: true }],
|
||||||
|
}
|
||||||
|
|
||||||
|
const servers = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }
|
||||||
|
|
||||||
|
// construct a new RTCPeerConnection
|
||||||
|
const pc = new RTCPeerConnection(servers, mediaConstraints)
|
||||||
|
|
||||||
|
let ips: any = []
|
||||||
|
|
||||||
|
// listen for candidate events
|
||||||
|
pc.onicecandidate = (ice) => {
|
||||||
|
// skip non-candidate events
|
||||||
|
if (ice.candidate) {
|
||||||
|
const ip = ipRegex.exec(ice.candidate.candidate)
|
||||||
|
if (ip !== null && ip.length > 1) {
|
||||||
|
ips.push(ip[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a bogus data channel
|
||||||
|
pc.createDataChannel('')
|
||||||
|
|
||||||
|
// create an offer sdp
|
||||||
|
pc.createOffer(
|
||||||
|
(result) => {
|
||||||
|
// trigger the stun server request
|
||||||
|
pc.setLocalDescription(
|
||||||
|
result,
|
||||||
|
() => {},
|
||||||
|
() => {}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
() => {}
|
||||||
|
)
|
||||||
|
|
||||||
|
const waitForElement = async () => {
|
||||||
|
if (pc.localDescription) {
|
||||||
|
const lines = pc.localDescription.sdp.split('\n')
|
||||||
|
lines.forEach((line) => {
|
||||||
|
if (line.indexOf('a=candidate:') === 0) {
|
||||||
|
const ip = ipRegex.exec(line)
|
||||||
|
if (ip !== null && ip.length > 1) {
|
||||||
|
ips.push(ip[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ips = [...new Set(ips)]
|
||||||
|
console.log(ips)
|
||||||
|
setWebRtcIp(await Promise.all(ips))
|
||||||
|
} else {
|
||||||
|
setTimeout(waitForElement, 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForElement()
|
||||||
|
// } else {
|
||||||
|
// setWebRTCData([])
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getWebRTC
|
||||||
17
src/Popup/Pages/WebRtcPage/handleWebRtcPolicy.ts
Normal file
17
src/Popup/Pages/WebRtcPage/handleWebRtcPolicy.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
const handleWebRtcPolicy = (value: string) => {
|
||||||
|
console.log(value)
|
||||||
|
chrome.privacy.network.webRTCIPHandlingPolicy.clear({}, () => {
|
||||||
|
chrome.privacy.network.webRTCIPHandlingPolicy.set(
|
||||||
|
{
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
webRtcPolicy: value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default handleWebRtcPolicy
|
||||||
67
src/Popup/Pages/WebRtcPage/index.tsx
Normal file
67
src/Popup/Pages/WebRtcPage/index.tsx
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { Box, Button, Select } from 'theme-ui'
|
||||||
|
import getWebRTCData from './getWebRTCData'
|
||||||
|
import handleWebRtcPolicy from './handleWebRtcPolicy'
|
||||||
|
|
||||||
|
interface LocationPageProps {
|
||||||
|
tab: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const WebRtcPage = ({ tab }: LocationPageProps) => {
|
||||||
|
const [webRtcPolicy, setWebRtcPolicy] = useState('default')
|
||||||
|
const [webRtcIp, setWebRtcIp] = useState([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
chrome.storage.sync.get(['webRtcPolicy'], (storage) => {
|
||||||
|
storage.webRtcPolicy && setWebRtcPolicy(storage.webRtcPolicy)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
chrome.privacy.network.webRTCIPHandlingPolicy.onChange.addListener(function (
|
||||||
|
details
|
||||||
|
) {
|
||||||
|
console.log(details)
|
||||||
|
setWebRtcPolicy(details.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: tab === 'webRtc' ? 'block' : 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ fontSize: '20px', mb: '8px' }}>WebRTC</Box>
|
||||||
|
<Select
|
||||||
|
name="webRtcPolicy"
|
||||||
|
id="webRtcPolicy"
|
||||||
|
value={webRtcPolicy}
|
||||||
|
onChange={(e) => handleWebRtcPolicy(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="default">Default</option>
|
||||||
|
<option value="default_public_and_private_interfaces">
|
||||||
|
Default public and private interfaces
|
||||||
|
</option>
|
||||||
|
<option value="default_public_interface_only">
|
||||||
|
Default public interface only
|
||||||
|
</option>
|
||||||
|
<option value="disable_non_proxied_udp">Disable non proxied udp</option>
|
||||||
|
</Select>
|
||||||
|
<Box sx={{ fontSize: '12px', mb: '8px' }}>
|
||||||
|
IP: {JSON.stringify(webRtcIp)}
|
||||||
|
</Box>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
getWebRTCData(setWebRtcIp)
|
||||||
|
// getWebRTCData().then((ip) => {
|
||||||
|
// console.log(ip)
|
||||||
|
// setWebRtcIp(ip)
|
||||||
|
// })
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reload
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WebRtcPage
|
||||||
|
|
@ -14,9 +14,11 @@ import TabItem from './TabItem'
|
||||||
import LocationPage from './Pages/LocationPage'
|
import LocationPage from './Pages/LocationPage'
|
||||||
import UserAgentPage from './Pages/UserAgentPage'
|
import UserAgentPage from './Pages/UserAgentPage'
|
||||||
import SettingsPage from './Pages/SettingsPage'
|
import SettingsPage from './Pages/SettingsPage'
|
||||||
|
import AddressAutofillPage from './Pages/AddressAutofillPage'
|
||||||
|
import WebRtcPage from './Pages/WebRtcPage'
|
||||||
|
|
||||||
const Popup = () => {
|
const Popup = () => {
|
||||||
const [tab, setTab] = useState('settings')
|
const [tab, setTab] = useState('webRtc')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
|
|
@ -41,13 +43,13 @@ const Popup = () => {
|
||||||
/>
|
/>
|
||||||
<TabItem
|
<TabItem
|
||||||
Icon={Home}
|
Icon={Home}
|
||||||
active={tab === 'AdressAutofill'}
|
active={tab === 'addressAutofill'}
|
||||||
onClick={() => setTab('AdressAutofill')}
|
onClick={() => setTab('addressAutofill')}
|
||||||
/>
|
/>
|
||||||
<TabItem
|
<TabItem
|
||||||
Icon={MessageSquare}
|
Icon={MessageSquare}
|
||||||
active={tab === 'WebRTC'}
|
active={tab === 'webRtc'}
|
||||||
onClick={() => setTab('WebRTC')}
|
onClick={() => setTab('webRtc')}
|
||||||
/>
|
/>
|
||||||
<TabItem
|
<TabItem
|
||||||
Icon={Sliders}
|
Icon={Sliders}
|
||||||
|
|
@ -66,6 +68,8 @@ const Popup = () => {
|
||||||
</Flex>
|
</Flex>
|
||||||
<Box sx={{ m: '12px', width: '100%' }}>
|
<Box sx={{ m: '12px', width: '100%' }}>
|
||||||
<LocationPage tab={tab} />
|
<LocationPage tab={tab} />
|
||||||
|
<AddressAutofillPage tab={tab} />
|
||||||
|
<WebRtcPage tab={tab} />
|
||||||
<UserAgentPage tab={tab} />
|
<UserAgentPage tab={tab} />
|
||||||
<SettingsPage tab={tab} />
|
<SettingsPage tab={tab} />
|
||||||
{/* <Text
|
{/* <Text
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export default setWebRtcPolicy
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es6",
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
"noEmit": false,
|
"noEmit": false,
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "theme-ui"
|
"jsxImportSource": "theme-ui"
|
||||||
|
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["build", "node_modules"]
|
"exclude": ["build", "node_modules"]
|
||||||
|
|
|
||||||
|
|
@ -1645,6 +1645,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.0.tgz#ed6ecaa8e5ed5dfe8b2b3d00181702c9925f13fb"
|
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.0.tgz#ed6ecaa8e5ed5dfe8b2b3d00181702c9925f13fb"
|
||||||
integrity sha512-56/MAlX5WMsPVbOg7tAxnYvNYMMWr/QJiIp6BxVSW3JJXUVzzOn64qW8TzQyMSqSUFM2+PVI4aUHcHOzIz/1tg==
|
integrity sha512-56/MAlX5WMsPVbOg7tAxnYvNYMMWr/QJiIp6BxVSW3JJXUVzzOn64qW8TzQyMSqSUFM2+PVI4aUHcHOzIz/1tg==
|
||||||
|
|
||||||
|
"@types/webrtc@^0.0.33":
|
||||||
|
version "0.0.33"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/webrtc/-/webrtc-0.0.33.tgz#8d5c64320741c9b0bd1cdd2890f12d9e6b5ae210"
|
||||||
|
integrity sha512-xjN6BelzkY3lzXjIjXGqJVDS6XDleEsvp1bVIyNccXCcMoTH3wvUXFew4/qflwJdNqjmq98Zc5VcALV+XBKBvg==
|
||||||
|
|
||||||
"@types/ws@^8.5.1":
|
"@types/ws@^8.5.1":
|
||||||
version "8.5.3"
|
version "8.5.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
|
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue