-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathnowebrtc.js
81 lines (75 loc) · 1.98 KB
/
nowebrtc.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable no-unused-vars, no-extra-bind, func-names */
import {
hit,
noopFunc,
logMessage,
convertRtcConfigToString,
} from '../helpers';
/* eslint-disable max-len */
/**
* @scriptlet nowebrtc
*
* @description
* Disables WebRTC by overriding `RTCPeerConnection`.
* The overridden function will log every attempt to create a new connection.
*
* Related UBO scriptlet:
* https://github.com/gorhill/uBlock/wiki/Resources-Library#nowebrtcjs-
*
* ### Syntax
*
* ```adblock
* example.org#%#//scriptlet('nowebrtc')
* ```
*
* @added v1.0.4.
*/
/* eslint-enable max-len */
export function nowebrtc(source) {
let propertyName = '';
if (window.RTCPeerConnection) {
propertyName = 'RTCPeerConnection';
} else if (window.webkitRTCPeerConnection) {
propertyName = 'webkitRTCPeerConnection';
}
if (propertyName === '') {
return;
}
const rtcReplacement = (config) => {
// eslint-disable-next-line max-len
const message = `Document tried to create an RTCPeerConnection: ${convertRtcConfigToString(config)}`;
logMessage(source, message);
hit(source);
};
rtcReplacement.prototype = {
close: noopFunc,
createDataChannel: noopFunc,
createOffer: noopFunc,
setRemoteDescription: noopFunc,
};
const rtc = window[propertyName];
window[propertyName] = rtcReplacement;
if (rtc.prototype) {
rtc.prototype.createDataChannel = function (a, b) {
return {
close: noopFunc,
send: noopFunc,
};
}.bind(null);
}
}
export const nowebrtcNames = [
'nowebrtc',
// aliases are needed for matching the related scriptlet converted into our syntax
'nowebrtc.js',
'ubo-nowebrtc.js',
'ubo-nowebrtc',
];
// eslint-disable-next-line prefer-destructuring
nowebrtc.primaryName = nowebrtcNames[0];
nowebrtc.injections = [
hit,
noopFunc,
logMessage,
convertRtcConfigToString,
];