Arya Singh
Arya Singh

Reputation: 11

How to load extension in playwright python

I want to load a extension but its not loading it.

  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)

Upvotes: 1

Views: 1863

Answers (1)

Mohamed Reda
Mohamed Reda

Reputation: 21

First, it is not possible to load an extension in incognito mode, so you must use playwright.chromium.launch_persistent_context instead of 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}",])

Upvotes: 1

Related Questions