2020-01-11 03:03:10 +03:00
|
|
|
# Bundling for Web
|
|
|
|
|
|
|
|
Playwright contains a version bundled for web browsers under `playwright/web.js`, which
|
|
|
|
installs playwright under `window.playwrightweb`.
|
|
|
|
You can use it in the web page to drive another browser instance.
|
|
|
|
|
2020-01-25 01:49:47 +03:00
|
|
|
API consists of a single `connect` function, similar to [browserType.connect(options)](api.md#browsertypeconnectoptions).
|
2020-01-11 03:03:10 +03:00
|
|
|
|
|
|
|
```html
|
2020-01-14 04:36:46 +03:00
|
|
|
<script src='playwright/web.js'></script>
|
2020-01-11 03:03:10 +03:00
|
|
|
<script>
|
|
|
|
async function usePlaywright() {
|
2020-01-14 04:36:46 +03:00
|
|
|
const browser = await window.playwrightweb.chromium.connect(options); // or 'firefox', 'webkit'
|
2020-01-11 03:03:10 +03:00
|
|
|
// ... drive automation ...
|
2020-02-06 23:41:43 +03:00
|
|
|
await browser.close();
|
2020-01-11 03:03:10 +03:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
|
|
|
See our [playwright-web tests](https://github.com/Microsoft/playwright/blob/master/test/web.spec.js) for example.
|
|
|
|
|
|
|
|
### Running inside Chrome Extension
|
|
|
|
|
|
|
|
You might want to enable `unsafe-eval` inside the extension by adding the following
|
|
|
|
to your `manifest.json` file:
|
|
|
|
|
|
|
|
```
|
|
|
|
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
|
|
|
|
```
|
|
|
|
|
|
|
|
Please see discussion in https://github.com/GoogleChrome/puppeteer/issues/3455.
|