Skip to content

[Question] Testing an extension's content-script #1083

Closed

Description

@gurupras

I have an extension that I would like to test using playwright. I'm currently able to load up my extension on Chromium as shown in the examples, but that's about all I can do at this point.

Creating a new page defaults to creating it in incognito mode, regardless of whether a BrowserContext is created or not. By default, extensions are disabled in incognito mode.. ergo my extension cannot be tested.

What am I doing wrong?

Activity

  1. gurupras commented on Feb 24, 2020

    @gurupras
    Author

    I think you missed my point. An incognito context has no extensions enabled. Even if I don't want to test my content script code, I can't even test for it's effects since it'll never run in an incognito context without me allowing my extension to run in incognito mode.
    Is there a way to do that programmatically? If not, then you can't test extensions using playwright 😕

  2. k15a commented on Feb 25, 2020

    @k15a

    I found a way to do that programmatically:

      await page.goto('chrome://extensions')
    
      const detailsButton = await page.evaluateHandle(() =>
        document
          .querySelector('body > extensions-manager')
          .shadowRoot.querySelector('#items-list')
          .shadowRoot.querySelector('extensions-item')
          .shadowRoot.querySelector('#detailsButton')
      )
    
      await detailsButton.click()
    
      const allowIncognitoButton = await page.evaluateHandle(() =>
        document
          .querySelector('body > extensions-manager')
          .shadowRoot.querySelector('#viewManager > extensions-detail-view')
          .shadowRoot.querySelector('#allow-incognito')
      )
    
      await allowIncognitoButton.click()
  3. pavelfeldman commented on Feb 27, 2020

    @pavelfeldman
    Member

    You should use chromium.launchPersistent to access default profile and test extension content scripts.

    Also, you can pierce shadow dom via:

    await page.click('css=body > extensions-manager >> css=#items-list >> css=extensions-item >> css=#detailsButton');

    (we'll get rid of those css= over time)

  4. 12masta commented on Jun 19, 2020

    @12masta
    Contributor

    Pavel Feldman (@pavelfeldman) chromium.launchPersistent works fine, but this function returns BrowserContext object, not Browser. It is causing issue which you have no access to Browser object to make some operation on background tab. Thoughts? Do you have some idea how to hande it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions