-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
124 lines (118 loc) · 4.01 KB
/
content.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(function() {
const assert = (value) => {
if (!value) {
throw new Error("Assertion failed in content.js");
}
};
const hasOwnProp = (obj, prop) => {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
const removedValues = {};
const remove = (path, grouping) => {
assert(Array.isArray(path) && path.length >= 1);
let object = window.wrappedJSObject;
for (let i = 0; i < path.length - 1; ++i) {
object = object[path[i]];
}
if (!hasOwnProp(removedValues, grouping)) {
removedValues[grouping] = [];
}
removedValues[grouping].push([path, Object.getOwnPropertyDescriptor(
object,
path[path.length - 1]
)
]);
delete object[path[path.length - 1]];
};
const restore = (grouping) => {
assert(hasOwnProp(removedValues, grouping));
for (let [path, descriptor] of removedValues[grouping]) {
if (descriptor === undefined) {
// Don't try to restore properties that were already gone
continue;
}
let object = window.wrappedJSObject;
for (let i = 0; i < path.length - 1; ++i) {
object = object[path[i]];
}
Object.defineProperty(object, path[path.length - 1], descriptor);
}
};
const bannedContexts = [
"webgl",
"experimental-webgl"
];
remove(["HTMLCanvasElement", "prototype", "getContext"], "webgl");
window.wrappedJSObject.HTMLCanvasElement.prototype.getContext = cloneInto(
function(ctxt) {
ctxt = ctxt.toString();
if (bannedContexts.includes(ctxt)) {
return null;
}
return window.HTMLCanvasElement.prototype.getContext.apply(
this,
arguments
);
},
window,
{ cloneFunctions: true }
);
remove(["WebGLRenderingContext"], "webgl");
remove(["WebGL2RenderingContext"], "webgl");
remove(["WebGLActiveInfo"], "webgl");
remove(["WebGLBuffer"], "webgl");
remove(["WebGLContextEvent"], "webgl");
remove(["WebGLFramebuffer"], "webgl");
remove(["WebGLProgram"], "webgl");
remove(["WebGLQuery"], "webgl");
remove(["WebGLRenderbuffer"], "webgl");
remove(["WebGLSampler"], "webgl");
remove(["WebGLShader"], "webgl");
remove(["WebGLShaderPrecisionFormat"], "webgl");
remove(["WebGLSync"], "webgl");
remove(["WebGLTexture"], "webgl");
remove(["WebGLTransformFeedback"], "webgl");
remove(["WebGLUniformLocation"], "webgl");
remove(["WebGLVertexArrayObject"], "webgl");
remove(["indexedDB"], "indexeddb");
remove(["IDBEnvironment"], "indexeddb");
remove(["IDBFactory"], "indexeddb");
remove(["IDBOpenDBRequest"], "indexeddb");
remove(["IDBDatabase"], "indexeddb");
remove(["IDBTransaction"], "indexeddb");
remove(["IDBRequest"], "indexeddb");
remove(["IDBObjectStore"], "indexeddb");
remove(["IDBIndex"], "indexeddb");
remove(["IDBCursor"], "indexeddb");
remove(["IDBCursorWithValue"], "indexeddb");
remove(["IDBKeyRange"], "indexeddb");
remove(["IDBLocaleAwareKeyRange"], "indexeddb");
remove(["IDBVersionChangeEvent"], "indexeddb");
remove(["IDBVersionChangeRequest"], "indexeddb");
remove(["IDBDatabaseException"], "indexeddb");
remove(["IDBTransactionSync"], "indexeddb");
remove(["IDBObjectStoreSync"], "indexeddb");
remove(["IDBIndexSync"], "indexeddb");
remove(["IDBFactorySync"], "indexeddb");
remove(["IDBEnvironmentSync"], "indexeddb");
remove(["IDBDatabaseSync"], "indexeddb");
remove(["IDBCursorSync"], "indexeddb");
remove(["IDBFileHandle"], "indexeddb");
remove(["IDBFileRequest"], "indexeddb");
remove(["IDBMutableFile"], "indexeddb");
remove(["Navigator", "prototype", "serviceWorker"], "serviceworkers");
remove(["ServiceWorker"], "serviceworkers");
remove(["ServiceWorkerContainer"], "serviceworkers");
remove(["ServiceWorkerRegistration"], "serviceworkers");
getFeaturesForURLString(window.location.href).then((features) => {
if (!features.nowebgl) {
restore("webgl");
}
if (!features.noindexeddb) {
restore("indexeddb");
}
if (!features.noserviceworkers) {
restore("serviceworkers");
}
});
})();