2023-08-31 15:55:22 +08:00

42 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Navigator = function Navigator() {
throw new TypeError('Illegal constructor')
}
catvm.safefunction(Navigator);
Object.defineProperties(Navigator.prototype, {
[Symbol.toStringTag]: {
value: 'Navigator',
configurable: true,
}
})
Object.getOwnPropertyDescriptor_ = Object.getOwnPropertyDescriptor;
Object.getOwnPropertyDescriptor = function (tag, val) {
// tag[Symbol.toStringtag]
if (tag.toLocaleString() == '[object Navigator]') {
return undefined;
}
return Object.getOwnPropertyDescriptor_.apply(this, arguments)
}
////////////////原型-补环境-start////////////////
Navigator.prototype.plugins = []
Navigator.prototype.language = ['zh-CN']
Navigator.prototype.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
////////////////原型-补环境-end//////////////////
// 解决实例可以调用属性,但是原型对象不能调用属性
navigator = {}
navigator.__proto__ = Navigator.prototype
// 遍历原型
for (let prototype_ in Navigator.prototype) {
// 将所有原型属性值赋值给实例属性值
navigator[prototype_] = Navigator.prototype[prototype_]
// hook所有的get属性值返回报错Illegal constructor
Navigator.prototype.__defineGetter__(prototype_, function () {
throw new TypeError('Illegal constructor')
})
}
navigator = catvm.proxy(navigator);