Rayrun
← Back to Discord Forum

chrome extension testing

Is anyone currently using playwright to test chrome extensions? I’m trying to do this at work and having a lot of issues. Googling this I’m finding some resources but not many. I’m basically trying to use the code from the playwright docs to get it working. https://playwright.dev/docs/chrome-extensions Bonus points if you’re using python but happy to discuss in js or ts.

This thread is trying to answer question "Is anyone currently using playwright to test chrome extensions?"

8 replies
rui.figueira
rui.figueira

I have some tests on chrome extensions and also had some issues, but they were mainly related with the extension service worker lifecycle

rui.figueira
rui.figueira
const worker = context.serviceWorkers()[0] ?? await context.waitForEvent('serviceworker');

    // wait for initialization
    await worker.evaluate(() => new Promise<void>((resolve, reject) => {
      if (serviceWorker.state !== 'activated') {
        serviceWorker.addEventListener('statechange', () => {
          if (serviceWorker.state === 'activated') resolve();
        });
        serviceWorker.addEventListener('error', reject);
      } else {
        resolve();
      }
    }));
rui.figueira
rui.figueira

another thing: that documentation is for manifest V2, not V3

rui.figueira
rui.figueira

in v3, they recommend service workers instead of backgroundPage

rui.figueira
rui.figueira

and in my case, I was using manifest v3

We’re also using V3 but the python documentation at least has the recommended service workers. Have you found any other good info sources on working with extensions in playwright? I’ve found a couple articles but not a lot. Once the kiddo is asleep I’ll check out your code more closely to see what I can glean.

rui.figueira
rui.figueira

no, my tests just needed to run some code in the worker, not much more

Thanks. That’s still good to know.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.