-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathdisable_WebRTC.js
More file actions
62 lines (56 loc) · 1.92 KB
/
disable_WebRTC.js
File metadata and controls
62 lines (56 loc) · 1.92 KB
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
// ==UserScript==
// @name 禁用WebRTC
// @description 阻止直播平台使用p2p(PCDN)技术占用上传
// @version 0.2
// @author zzc10086
// @license MIT
// @namespace https://github.com/zzc10086/grocery_store
// @match http*://*.bilibili.com/*
// @match http*://*.huya.com/*
// @match http*://*.douyu.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
const webrtcKeys = new Set([
"RTCCertificate", "RTCDataChannel", "RTCIceCandidate", "RTCIceTransport",
"RTCPeerConnection", "RTCRtpReceiver", "RTCSessionDescription",
"mozRTCIceCandidate", "mozRTCPeerConnection", "mozRTCSessionDescription",
"webkitRTCPeerConnection", "RTCIceServer", "RTCStatsReport"
]);
// 1. 禁用当前窗口的 WebRTC 属性
webrtcKeys.forEach(key => {
if (window[key]) {
try {
Object.defineProperty(window, key, {
value: undefined,
writable: false,
configurable: false
});
} catch (e) {
delete window[key];
}
}
});
//b站会检测iframe的window对象来判断当前页面是否被hack
const originalContentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow').get;
Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
configurable: false,
enumerable: true,
get: function() {
const win = originalContentWindow.call(this);
if (!win) return win;
return new Proxy(win, {
get(target, prop) {
if (webrtcKeys.has(prop)) {
return undefined;
}
const value = Reflect.get(target, prop);
if (typeof value === 'function') {
return value.bind(target);
}
return value;
}
});
}
});
console.log("已拦截 WebRTC 相关接口");