-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinjectedScript.js
35 lines (29 loc) · 1.1 KB
/
injectedScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const inject =
'(' +
function () {
window._webrtc_getstats = {
peerConnections: [],
rtcRtpSenderStats: {}
}
// Pushes every newly created RTCPeerConnection to an array.
class customRTCPeerConnection extends RTCPeerConnection {
constructor (configuration) {
console.log('New PeerConnection !')
super(configuration)
window._webrtc_getstats.peerConnections.push(this)
}
}
window.RTCPeerConnection = customRTCPeerConnection
} +
')();'
// This script must be run before everything else because we overwrite
// RTCPeerConnection.
const injectedScript = document.createElement('script')
injectedScript.textContent = inject
const parentNode = document.head || document.documentElement
parentNode.insertBefore(injectedScript, parentNode.firstChild)
injectedScript.parentNode.removeChild(injectedScript)
const mainScript = document.createElement('script')
mainScript.setAttribute('type', 'text/javascript')
mainScript.setAttribute('src', chrome.extension.getURL('content.js'));
(document.head || document.documentElement).appendChild(mainScript)