Playwright その他の操作
Playwrightで表示するchromium/chromeのユーザーデータの保存場所を指定する
Playwrightで起動したChromiumやChromeのユーザーデータの保存場所は毎回異なるので、Cookieや認証情報が無効になります。
オプションで保存場所を指定することでユーザーデータの使いまわしができます。
サンプル
const pw = require('playwright'); (async () => { const browser = await pw.chromium.launchPersistentContext('c:/chrome/profile', { headless: false }); //const context = await browser.newContext(); //const page = await context.newPage(); const page = await browser.newPage(); await page.goto('https://web.biz-prog.net/test/testpage.html'); await browser.close(); })();
private async void btnUserData_Click(object sender, EventArgs e) { using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchPersistentContextAsync( @"C:\chrome\profile", new BrowserTypeLaunchPersistentContextOptions { Headless = false } ); var page = await browser.NewPageAsync(); await page.GotoAsync("https://web.biz-prog.net/test/testpage.html"); }
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError with sync_playwright() as p: browser = p.chromium.launch_persistent_context("c:/chrome/profile", headless = False ); page = browser.new_page() page.goto("https://web.biz-prog.net/test/testpage.html") browser.close()