Repository: puppeteer
Issue: [Bug]: `TypeError: Cannot convert undefined or null to object` with resolve argument of a Promise
Labels: bug,P1,confirmed

### Minimal, reproducible example

```TypeScript
import puppeteer from "puppeteer";

function createPromise(page, callback) {
  return page.evaluateHandle(
    // eslint-disable-next-line no-eval
    cb => [new Promise(eval(`(${cb})`))],
    callback.toString()
  );
}

function awaitPromise(promise) {
  return promise.evaluate(([p]) => p);
}

const browser = await puppeteer.launch({
  browser: "chrome",
  headless: false,
  protocol: "webDriverBiDi",
});

const page = await browser.newPage();
await page.goto("https://mozilla.github.io/pdf.js/web/viewer.html");
await page.bringToFront();

const handle = await createPromise(page, resolve => {
  window.PDFViewerApplication.eventBus.on("textlayerrendered", resolve, { once: true });
});
await awaitPromise(handle);

await page.close();
await browser.close();
```


### Background

This bug was previously fixed in #12111, but unfortunately it seems like it has returned. This was found in the context of https://github.com/mozilla/pdf.js/issues/17961 where we try to enable WebDriverBidi for Chrome in the Mozilla PDF.js project again, and currently lots of test fail because of this.

Steps to reproduce:

1. Save the reproducible example as `repro.js`.
2. Run `npm install puppeteer` (to install the latest version).
3. Run `node repro.js` and notice the traceback.

Note that this only fails for Chrome with WebDriverBiDi. It works for Firefox with WebDriverBiDi and for Chrome with CDP.

### Expectation

The script doesn't log anything.

### Reality

The script logs the following traceback for Chrome with WebDriverBiDi:

```
file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:97
    #error = new ProtocolError();
             ^

ProtocolError: Protocol error (script.callFunction): unknown error Cannot convert undefined or null to object TypeError: Cannot convert undefined or null to object
    at Function.hasOwn (<anonymous>)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/Realm.js:65:20)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/WindowRealm.js:93:22)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/Realm.js:88:26)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/WindowRealm.js:93:22)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/Realm.js:88:26)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/WindowRealm.js:93:22)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/Realm.js:88:26)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/WindowRealm.js:93:22)
    at WindowRealm.serializeForBiDi (/home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/chromium-bidi/lib/cjs/bidiMapper/modules/script/Realm.js:88:26)
    at <instance_members_initializer> (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:97:14)
    at new Callback (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:101:16)
    at CallbackRegistry.create (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:20:26)
    at BidiConnection.send (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/bidi/Connection.js:51:32)
    at Session.send (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/bidi/core/Session.js:134:42)
    at Session.<anonymous> (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/util/decorators.js:101:27)
    at WindowRealm.callFunction (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/bidi/core/Realm.js:92:51)
    at WindowRealm.<anonymous> (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/util/decorators.js:101:27)
    at #evaluate (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/bidi/Realm.js:134:42)
    at BidiFrameRealm.evaluate (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/node_modules/puppeteer-core/lib/esm/puppeteer/bidi/Realm.js:104:36)
```

### Puppeteer configuration file (if used)

_No response_

### Puppeteer version

23.11.1

### Node version

23.4.0

### Package manager

npm

### Package manager version

10.9.2

### Operating system

Linux