ruifigueira / playwright-crx

Playwright for chrome extensions
Apache License 2.0
116 stars 20 forks source link

[Feature] Allow tracing #7

Open ruifigueira opened 11 months ago

ruifigueira commented 11 months ago

With memfs we can get tracings. It captures screenshots but no snapshots.

Here is an example (it opens the memfs file in trace.playwright.dev):

test('should trace', async ({ runCrxTest, _extensionServiceWorkerDevtools }) => {
  await runCrxTest(async ({ crxApp, page, context }) => {
    await context.tracing.start({ snapshots: true, screenshots: true, sources: true });
    await page.goto('https://demo.playwright.dev/todomvc/#/');
    await page.getByPlaceholder('What needs to be done?').fill('Playwright CRX rocks!');
    await page.getByPlaceholder('What needs to be done?').press('Enter');
    await page.getByLabel('Toggle Todo').click();
    await page.getByRole('button', { name: 'Clear completed' }).click();
    await context.tracing.stop({ path: '/crx/trace.zip' });

    const tracePage = await crxApp.newPage();
    await tracePage.goto('https://trace.playwright.dev');

    const [chooser] = await Promise.all([
      tracePage.waitForEvent('filechooser'),
      tracePage.getByRole('button', { name: 'Select file(s)' }).click(),
    ]);
    await chooser.setFiles('/crx/trace.zip');
    debugger;
  });
});

Problem seems to be related with the way playwright determines the API name.

Basically, it uses the stacktrace but because we're using vite, which compiles to a single file, it's not able to determine the api name and, without it, it doesn't trigger the instrumentation events.