CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

[Playwright] When using connect over cdp option, failed to access default browser context

Open HaruhikoKubo opened this issue 1 year ago • 1 comments

What are you trying to achieve?

Try to use browserWSEndpoint with cdpConnection option for browser extension test.

What do you get instead?

Now during the before section, we create a new context in this.browserContext = await this.browser.newContext(contextOptions); https://github.com/codeceptjs/CodeceptJS/blob/3.x/lib/helper/Playwright.js#L490 Then we got 1 normal window and 1 incognito window when we use cdp option. The normal window has chrome extension but not accessible from the context. We can access to incognito window from context but we cannot use an extension since an extension should be allowed in incognito mode in a normal window.

However from playwright help, seems we need to use browser.contexts() to access default browser context. https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp like this.browserContext = await this.browser.contexts()[0]

Details

  • CodeceptJS version: 3.5.3
  • NodeJS Version: 16.13.1
  • Operating System: Mac
  • Playwright: 1.36.2
  • Configuration file:
# paste config here

here is the playwright option { url: baseUrl, show: true, trace: true, restart: "context", disableScreenshots: true, browser: "chromium", basicAuth: { username: process.env.BASIC_AUTH_USER || "", password: process.env.BASIC_AUTH_PASSWORD || "", }, chromium: { cdpConnection: true, browserWSEndpoint: { wsEndpoint: wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent( JSON.stringify(caps) )}, }, args: [ "--start-maximized", ], }, channel: "chrome", }

HaruhikoKubo avatar Aug 21 '23 12:08 HaruhikoKubo

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Nov 20 '23 02:11 github-actions[bot]