如何在 playwright python 中加载扩展

问题描述 投票:0回答:1

我想加载扩展程序,但它没有加载它。

  with sync_playwright() as p:
            extension_path = r"C:\Users\hpary\AppData\Local\BraveSoftware\Brave-Browser\User Data\Profile 6\Extensions\pabjfbciaedomjjfelfafejkppknjleh\1.8.7_0"
            browserx = p.chromium.launch(headless=False,
            args=[
                f"--disable-extensions-except={extension_path}",
                f"--load-extension={extension_path}",
            ]
        )
            # browserx = pal
            browser = browserx.new_context()#proxy={"server":f"http://{proxy}"}#record_video_dir=None,java_script_enabled=True,ignore_https_errors=True
            page = browser.new_page()
            print(f"{Fore.CYAN}[LAUNCHED] {Fore.RESET}Browser {id} Launched Suchcessfully....")
            page.goto(url, wait_until='networkidle', timeout=20000)
            page.wait_for_timeout(5000)
            time.sleep(5)
python browser automation
1个回答
0
投票

首先,无法在隐身模式下加载扩展,因此您必须使用 playwright.chromium.launch_persistent_context 而不是 playwright.chromium.launch

path=os.getenv("LOCALAPPDATA")
full_path=os.path.join(path,'chromium\\User Data\\Default')
path_to_extension=r'the path to the extension'
playwright=sync_playwright().start()
context=playwright.chromium.launch_persistent_context(
          user_data_dir=full_path,
          headless=False,
          channel='chrome',
          args=[
            f"--disable-extensions-except={path_to_extension}",
            f"--load-extension={path_to_extension}",])
© www.soinside.com 2019 - 2024. All rights reserved.