Closed atsakiridis closed 11 months ago
@atsakiridis If you're testing extension, you should use headless=new
chromium mode, see https://playwright.dev/docs/next/chrome-extensions#headless-mode
This way chrome extension will always be loaded. Hope this helps!
@aslushnikov thanks for your reply, but I'm already following playwright docs for extensions and using headless=new
. Remember, the exact same tests pass in headless mode when not using docker as I mentioned. Here's the launch code in my fixture:
...
const pathToExtension = 'extensions/efbglgofoippbgcjepnhiblaibcnclgk/1.6.16_0';
const context = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--headless=new`,
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
]
});
So it must be something specific for docker... Any clues?
So it must be something specific for docker... Any clues?
@atsakiridis Some usual suspects are incorrectly mounted docker volumes, but I'm out of ideas otherwise. if you do think this is Playwright's fault, please file a new issue with a good repro for us to debug!
Seems like I have the same issue: an extension which tests are successful in local environment both for headless and headful modes, but failing inside Docker container. My research showed that the problem (at least for me) is in background service worker which is not starting. I'm using this code for getting extension's id and all tests failing on waiting for the serviceworker event due to exceeding timeout:
...
extensionId: async ({ context }, use) => {
let [background] = context.serviceWorkers();
if (!background) background = await context.waitForEvent('serviceworker');
const extensionId = background.url().split('/')[2];
await use(extensionId);
},
...
I've also experienced the same problem. However, there is a workaround for that.
You can use "user flow" and get id through UI. Here's how you can achieve that:
await page.goto("chrome://extensions/");
await page.locator("#detailsButton").click();
const href = await page.evaluate(() => document.location.href);
const url = new URLSearchParams(href);
const extensionId = url.get("chrome://extensions/?id");
await use(extensionId);
Side note: only one extension has to be installed (if you have more, you need to add more steps to filter extension you are interested in).
Tested on Docker and Gitlab CI in Headless mode and works.
System info
Source code
I'm afraid I can't share the full source code, but I could share some snippets if you tell me what you want to look at
Config file
Steps
Expected
I'm expecting the test to pass
Actual
Instead, the test times out waiting for the extension popup to come up
Important notes:
Comparing chrome logs between successful and failed runs, what stands out are these lines:
Can you think of any reason why headless docker run might mess with extension popup or not allow it to come up?