Playwright giving me hard time running a browser on existing chrome profile

1 day ago 3
ARTICLE AD BOX

I have been browsing through web, debugging with llms but not able to resolve this simple thing.

Here's my code:

// @ts-check import { chromium, test } from '@playwright/test'; import { rmSync } from 'fs'; import os from 'os'; import path from 'path'; test('open gemini with existing chrome profile', async () => { const userDataDir = path.join( os.homedir(), 'AppData', 'Local', 'Google', 'Chrome', 'User Data' ); // Remove stale lock/session files that can cause launchPersistentContext to timeout for (const file of ['SingletonLock', 'SingletonCookie', 'SingletonSocket']) { try { rmSync(path.join(userDataDir, file), { force: true }); } catch { } } const context = await chromium.launchPersistentContext(userDataDir, { channel: 'chrome', headless: false, args: ['--profile-directory=Profile 2'], }); const page = context.pages().at(0) ?? (await context.newPage()); await page.goto('https://gemini.google.com/', { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(8000); await context.close(); });

I need to open gemini via playwright but using my existing browser context (Profile 2)

But its giving me super hard time. Here's the debugging logs:

Search tests open gemini with existing chrome profile example.spec.js:7 30.0s chrome-profile-2 Copy prompt Test timeout of 30000ms exceeded. Filter steps Before Hooks 14ms Launch persistent context— example.spec.js:22 - 21 | 22 | const context = await chromium.launchPersistentContext(userDataDir, { | ^ 23 | channel: 'chrome', After Hooks 32ms Worker Cleanup 2ms error-context

Can someone help?

I am running it on windows machine and playwright version is 1.59.1 . Chrome version: 146.0.7680.178

Also its a org managed browser but I hope that should be fine.

So I am able to see playwright launching the browser with my user profile but nothing beyond that.

Read Entire Article