Ⅰ. はじめに
タイトルの通り「Playwrightを利用してWebページのスクリーンショットを撮る方法」です。
Ⅱ. やり方
1. Playwrightをインストールする
npm i -D playwright
2. サンプルプログラムを書く
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://example.com') await page.screenshot({ path: `images/${browserType}.png` }) await browser.close() } })()
実行結果