方法一:
from playwright.sync_api import Playwright, sync_playwright
playwright = sync_playwright().start()
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
# # 关闭Webdriver属性
js = """
Object.defineProperties(navigator, {webdriver:{get:()=>undefined}});
"""
page.add_init_script(js)
方法二:
context.add_init_script("Object.defineProperties(navigator, {webdriver:{get:()=>false}});")
context.add_init_script("const newProto = navigator.__proto__; delete newProto.webdriver; navigator.__proto__ = newProto;")
网友评论