Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions nodejs/docs/chrome-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import HTMLCard from '@site/src/components/HTMLCard';
Extensions only work in Chrome / Chromium launched with a persistent context. Use custom browser args at your own risk, as some of them may break Playwright functionality.
:::

The snippet below retrieves 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`.
The snippet below retrieves the [service worker](https://developer.chrome.com/docs/extensions/develop/concepts/service-workers) of a [Manifest v3](https://developer.chrome.com/docs/extensions/develop/migrate) extension whose source is located in `./my-extension`.

Note the use of the `chromium` channel that allows to run extensions in headless mode. Alternatively, you can launch the browser in headed mode.

Expand All @@ -30,11 +30,11 @@ const { chromium } = require('playwright');
`--load-extension=${pathToExtension}`
]
});
let [backgroundPage] = browserContext.backgroundPages();
if (!backgroundPage)
backgroundPage = await browserContext.waitForEvent('backgroundpage');
let [serviceWorker] = browserContext.serviceWorkers();
if (!serviceWorker)
serviceWorker = await browserContext.waitForEvent('serviceworker');

// Test the background page as you would any other page.
// Test the service worker as you would any other worker.
await browserContext.close();
})();
```
Expand Down Expand Up @@ -68,19 +68,12 @@ export const test = base.extend<{
await context.close();
},
extensionId: async ({ context }, use) => {
/*
// for manifest v2:
let [background] = context.backgroundPages()
if (!background)
background = await context.waitForEvent('backgroundpage')
*/

// for manifest v3:
let [background] = context.serviceWorkers();
if (!background)
background = await context.waitForEvent('serviceworker');
let [serviceWorker] = context.serviceWorkers();
if (!serviceWorker)
serviceWorker = await context.waitForEvent('serviceworker');

const extensionId = background.url().split('/')[2];
const extensionId = serviceWorker.url().split('/')[2];
await use(extensionId);
},
});
Expand Down
2 changes: 1 addition & 1 deletion nodejs/docs/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pnpm exec playwright --version
</Tabs>

## System requirements
- Latest version of Node.js 18, 20 or 22.
- Latest version of Node.js 20, 22 or 24.
- Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
- macOS 14 Ventura, or later.
- Debian 12, Ubuntu 22.04, Ubuntu 24.04, on x86-64 and arm64 architecture.
Expand Down
1 change: 1 addition & 0 deletions nodejs/docs/test-reporters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ HTML report supports the following configuration options and environment variabl
| `PLAYWRIGHT_HTML_HOST` | `host` | When report opens in the browser, it will be served bound to this hostname. | `localhost`
| `PLAYWRIGHT_HTML_PORT` | `port` | When report opens in the browser, it will be served on this port. | `9323` or any available port when `9323` is not available.
| `PLAYWRIGHT_HTML_ATTACHMENTS_BASE_URL` | `attachmentsBaseURL` | A separate location where attachments from the `data` subdirectory are uploaded. Only needed when you upload report and `data` separately to different locations. | `data/`
| `PLAYWRIGHT_HTML_NO_SNIPPETS` | `noSnippets` | If true, disable rendering code snippets in the action log. If there is a top level error, that report section with code snippet will still render. Supports `true`, `1`, `false`, and `0`. | `false`

### Blob reporter

Expand Down
31 changes: 13 additions & 18 deletions python/docs/chrome-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import HTMLCard from '@site/src/components/HTMLCard';
Extensions only work in Chrome / Chromium launched with a persistent context. Use custom browser args at your own risk, as some of them may break Playwright functionality.
:::

The snippet below retrieves 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`.
The snippet below retrieves the [service worker](https://developer.chrome.com/docs/extensions/develop/concepts/service-workers) of a [Manifest v3](https://developer.chrome.com/docs/extensions/develop/migrate) extension whose source is located in `./my-extension`.

Note the use of the `chromium` channel that allows to run extensions in headless mode. Alternatively, you can launch the browser in headed mode.

Expand Down Expand Up @@ -43,12 +43,12 @@ def run(playwright: Playwright):
f"--load-extension={path_to_extension}",
],
)
if len(context.background_pages) == 0:
background_page = context.wait_for_event('backgroundpage')
if len(context.service_workers) == 0:
service_worker = context.wait_for_event('serviceworker')
else:
background_page = context.background_pages[0]
service_worker = context.service_workers[0]

# Test the background page as you would any other page.
# Test the service worker as you would any other worker.
context.close()


Expand Down Expand Up @@ -77,12 +77,12 @@ async def run(playwright: Playwright):
],
)

if len(context.background_pages) == 0:
background_page = await context.wait_for_event('backgroundpage')
if len(context.service_workers) == 0:
service_worker = await context.wait_for_event('serviceworker')
else:
background_page = context.background_pages[0]
service_worker = context.service_workers[0]

# Test the background page as you would any other page.
# Test the service worker as you would any other worker.
await context.close()


Expand Down Expand Up @@ -129,17 +129,12 @@ def context(playwright: Playwright) -> Generator[BrowserContext, None, None]:

@pytest.fixture()
def extension_id(context) -> Generator[str, None, None]:
# for manifest v2:
# background = context.background_pages[0]
# if not background:
# background = context.wait_for_event("backgroundpage")

# for manifest v3:
background = context.service_workers[0]
if not background:
background = context.wait_for_event("serviceworker")
service_worker = context.service_workers[0]
if not service_worker:
service_worker = context.wait_for_event("serviceworker")

extension_id = background.url.split("/")[2]
extension_id = service_worker.url.split("/")[2]
yield extension_id

```
Expand Down
Loading