ruifigueira / playwright-crx

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

[Bug] We are unable to take screenshot after the commit 18ca4ea #14

Closed ekingunoncu closed 7 months ago

ekingunoncu commented 7 months ago

Hello Rui,

I hope you are doing well. After the below commit 18ca4ea we are unable to take screenshots.

We are getting the error below:

background.js:83769 Uncaught Error: binary: expected base64-encoded buffer, got object
    at tBinary (background.js:83769:11)
    at background.js:83808:22
    at CrxConnection.dispatch (background.js:118150:26)
    at CrxConnection.dispatch (background.js:118434:18)
    at background.js:135631:83
    at run (background.js:312:9)
    at runIfPresent (background.js:336:11)
    at channel.port1.onmessage (background.js:383:7)
tBinary @ background.js:83769
(anonymous) @ background.js:83808
dispatch @ background.js:118150
dispatch @ background.js:118434
(anonymous) @ background.js:135631
run @ background.js:312
runIfPresent @ background.js:336
channel.port1.onmessage @ background.js:383

It was working on the commit d808a75

The issue is not reproducible via unit tests, for example, the below code takes the screenshot:

test("test screenshot", async ({ page }) => {
  await page.goto("https://example.com");
  const screenshot = await page.screenshot();
  expect(screenshot).not.toBeNull();
});

To reproduce the issue we have to load it as an extension to chrome. We can simply add before createTodos

.
.
.
await page.screenshot();
await createTodos(page);

I believe the change was the playwright's version. Since the difference is huge and the change caused the issue is not on our side I don't know where to look for the fix.

I would love to help if you can give me a direction. Thanks in advance, Best regards,

Ekin

ruifigueira commented 7 months ago

Hmm, you're right. As reference, here's the test I used:

test("should take screenshot", async ({ runCrxTest }) => {
  await runCrxTest(async ({ expect, page, server }) => {
    await page.goto(server.EMPTY_PAGE);
    await page.setContent('<h1>Hello World!</h1>');
    const screenshot = await page.screenshot();
    expect(screenshot).not.toBeNull();
  });
});

and the stacktrace with sourcemap:

validatorPrimitives.ts:68 Uncaught Error: binary: expected base64-encoded buffer, got object
    at tBinary (validatorPrimitives.ts:68:11)
    at validatorPrimitives.ts:112:21
    at CrxConnection.dispatch (connection.ts:161:26)
    at CrxConnection.dispatch (crxConnection.ts:51:18)
    at index.ts:46:81
    at run (setImmediate.js:40:13)
    at runIfPresent (setImmediate.js:69:21)
    at channel.port1.onmessage (setImmediate.js:128:13)
ruifigueira commented 7 months ago

I already fixed the bug, and I'm going to release a new version today or tomorrow with playwright 1.42.0

ruifigueira commented 7 months ago

I just released 0.4.0

ekingunoncu commented 7 months ago

Thank you very much!