| Jun | JUL | Aug |
| 09 | ||
| 2019 | 2020 | 2021 |
COLLECTED BY
Collection: github.com
This includes page CDPSession, backgroundPages() and serviceWorkers(). This has also revealed an issue with closing order between the context and the service worker.
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium 86.0.4197.0 | |||
| WebKit 14.0 | |||
| Firefox 78.0b5 |
npm i -D playwright
This installs Playwright and browser binaries for Chromium, Firefox and WebKit. Once installed, you can require Playwright in a Node.js script and automate web browser interactions.
●Getting started
●Installation configuration
●API reference
const playwright = require('playwright'); (async () => { for (const browserType of ['chromium', 'firefox', 'webkit']) { const browser = await playwright[browserType].launch(); const context = await browser.newContext(); const page = await context.newPage(); await page.goto('http://whatsmyuseragent.org/'); await page.screenshot({ path: `example-${browserType}.png` }); await browser.close(); } })();
const { webkit, devices } = require('playwright'); const iPhone11 = devices['iPhone 11 Pro']; (async () => { const browser = await webkit.launch(); const context = await browser.newContext({ ...iPhone11, locale: 'en-US', geolocation: { longitude: 12.492507, latitude: 41.889938 }, permissions: ['geolocation'] }); const page = await context.newPage(); await page.goto('https://maps.google.com'); await page.click('text="Your location"'); await page.waitForRequest(/.*preview\/pwa/); await page.screenshot({ path: 'colosseum-iphone.png' }); await browser.close(); })();
const { firefox } = require('playwright'); (async () => { const browser = await firefox.launch(); const context = await browser.newContext(); const page = await context.newPage(); await page.goto('https://www.example.com/'); const dimensions = await page.evaluate(() => { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, deviceScaleFactor: window.devicePixelRatio } }); console.log(dimensions); await browser.close(); })();
const { webkit } = require('playwright'); (async () => { const browser = await webkit.launch(); const context = await browser.newContext(); const page = await context.newPage(); // Log and continue all network requests page.route('**', route => { console.log(route.request().url()); route.continue(); }); await page.goto('http://todomvc.com'); await browser.close(); })();