Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs(chrome-extensions-js-python.md) add headless testing docs (#19812)
Boris Osipov90af7a7ee0d0
diff --git a/docs/src/chrome-extensions-js-python.md b/docs/src/chrome-extensions-js-python.mdindex 648d4b3b85..94918417d4 100644--- a/docs/src/chrome-extensions-js-python.md+++ b/docs/src/chrome-extensions-js-python.md@@ -4,7 +4,7 @@ title: "Chrome Extensions"---:::note-Extensions only work in Chrome / Chromium in non-headless mode, launched with a persistent context.+Extensions only work in Chrome / Chromium launched with a persistent context.:::The following is code for getting a handle to the [background page](https://developer.chrome.com/extensions/background_pages) of a [Manifest v2](https://developer.chrome.com/docs/extensions/mv2/) extension whose source is located in `./my-extension`:@@ -212,3 +212,36 @@ def test_popup_page(page: Page, extension_id: str) -> None:page.goto(f"chrome-extension://{extension_id}/popup.html")expect(page.locator("body")).to_have_text("my-extension popup")```++## Headless mode++By default, Chrome's headless mode in Playwright does not support Chrome extensions. To overcome this limitation, you can run Chrome's persistent context with a new headless mode by using the following code:+```ts+// fixtures.ts+// ...++const pathToExtension = path.join(__dirname, 'my-extension');+const context = await chromium.launchPersistentContext('', {+ headless: false,+ args: [+ `--headless=chrome`, // the new headless arg+ `--disable-extensions-except=${pathToExtension}`,+ `--load-extension=${pathToExtension}`,+ ],+});+// ...+```++```python+# conftest.py+path_to_extension = Path(__file__).parent.joinpath("my-extension")+context = playwright.chromium.launch_persistent_context(+ "",+ headless=False,+ args=[+ "--headless=chrome", # the new headless arg+ f"--disable-extensions-except={path_to_extension}",+ f"--load-extension={path_to_extension}",+ ],+)+```\ No newline at end of file