def init_js(page: Page, phone: str) -> Page:
#修改 网页 navigator 的属性的值
function fakeNav(key, value) {
Object.defineProperty(navigator, key, {
value: value,
writable: false
});
}
js_device_memory = f'fakeNav("deviceMemory", {gen_android_memory(phone)})'
js_do_not_track = 'fakeNav("doNotTrack", null)'
# 引用 stealth.min.js
with open(r"D:\stealth.min.js") as file:
js_fake_file = file.read()
page.add_init_script(js_fake_file)
return page