Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Setting up an environment with persistentContext #188

@karthikiyengar

Description

@karthikiyengar

Is your feature request related to a problem? Please describe.
In order to test Chrome Extensions (and other persistent use cases), it would be nice if chrome can be launched in persistent mode. Explicitly passing a userDataDir to launch results in
userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead

Describe the solution you'd like

Some way or flag to override https://github.com/playwright-community/jest-playwright/blob/master/src/PlaywrightEnvironment.ts#L32 and use launchPersistentContext instead of launch. It can be as simple as the following, although it must be noted that we will no longer comply with playwright's launch options.

if (launchOptions.userDataDir != null) {
  return playwrightInstance.launch(launchOptions.userDataDir, options)
}

An alternative would be to create a new option along the lines of persistentDataDir.

This would allow us to setup a custom environment for extensions like so:

class CustomEnvironment extends PlaywrightEnvironment {
  async setup() {
    await super.setup()
    let popupPageUrl

    const backgroundPage = await this.global.browser.waitForEvent('backgroundpage') // this is only available via chromium.launchPersistentContext
    const extensionId = backgroundPage.url().split('/')[2]
    popupPageUrl = `chrome-extension://${extensionId}/popup.html#`

    this.global.page.gotoPopup = function (url, options = {}) {
      const paddedUrl = !url.startsWith('/') ? `/${url}` : url
      return page.goto(popupPageUrl + paddedUrl, options)
    }
  }

  async teardown() {
    // Your teardown
    await super.teardown()
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions