Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeError: Cannot convert undefined or null to object with resolve argument of a Promise #13433

Open
timvandermeij opened this issue Dec 21, 2024 · 2 comments

Comments

@timvandermeij
Copy link

timvandermeij commented Dec 21, 2024

Minimal, reproducible example

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 mozilla/pdf.js#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

@timvandermeij timvandermeij changed the title [Bug]: TypeError: Cannot convert undefined or null to object with resolve argument of a Promise [Regression]: TypeError: Cannot convert undefined or null to object with resolve argument of a Promise Dec 21, 2024
@timvandermeij
Copy link
Author

timvandermeij commented Dec 21, 2024

I think the problem is that the check introduced in https://github.com/GoogleChromeLabs/chromium-bidi/pull/2039/files is not present in Realm.js at https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/src/bidiMapper/modules/script/Realm.ts#L122. I tried introducing it locally and that seems to fix the issue, but note that I can't really tell if this is a good fix or not because I don't know the context of this code.

/cc @OrKoN @jrandolf-2 as authors of the original PR since you probably know much more about this code than I do.

@timvandermeij timvandermeij changed the title [Regression]: TypeError: Cannot convert undefined or null to object with resolve argument of a Promise [Bug]: TypeError: Cannot convert undefined or null to object with resolve argument of a Promise Dec 21, 2024
@OrKoN
Copy link
Collaborator

OrKoN commented Dec 22, 2024

Thanks for filing the issue once again. Indeed it regressed due to the lack of test coverage. I am adding a WPT test and a fix into chromium-bidi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants