Puppeteer: why is there a "Protocol error (Runtime.callFunctionOn): Target closed"?
Asked Answered
D

1

0

I'm a newbie with Puppeteer but I try to use it to run my E2E tests.
My JS runtime is Bun (v.0.6.9) and puppeteer should work.

Below, a simple test throwing a puppeteer error I can't fix.

describe('A test', async () => {

  const browser = await puppeteer.launch({ defaultViewport: null, headless: false })

  const page = await browser.newPage()

  beforeEach(async () => await page.goto('http://localhost:3000'))
  afterEach(async () => await page.close())
  afterAll(async () => await browser.close())

  it('should learn puppeteer', async () => {

    console.log(page.url())                  // it works (log: http://localhost:3000/)

    const source = await page.content();
    console.log(source)                     // it works

    page
      .click('input[type="submit"]')
      .then(() => console.log('got it'))
      .catch((e) => console.log(e))        // it throws

    console.log('this line is logged')     // this line is logged
    expect(1).toBe(1)                      // this test pass
  })
})

The error:

34 |     /**
35 |      * @internal
36 |      */
37 |     constructor(message) {
38 |         super(message);
39 |         this.name = this.constructor.name;
                ^
TargetCloseError: Protocol error (Runtime.callFunctionOn): Target closed
 code: "undefined"

      at /Users/charnould/GitHub/malro/node_modules/puppeteer-core/lib/esm/puppeteer/common/Errors.js:39:13

Do you have any clue?

Nota: My webpage (http://localhost:3000) do include somewhere: <input type="submit" value="Login">

Dougherty answered 17/6, 2023 at 12:21 Comment(0)
D
0

Fixed by Bun with 0.6.10.
See this GitHub issue.

Dougherty answered 27/6, 2023 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.