(Created on )

Puppeteer: Cannot adopt DOM nodes into a worker.

A DOM node handle is being adopted into a worker realm.


A DOM node handle is being adopted into a worker realm.

Error message

Cannot adopt DOM nodes into a worker.

How this error happens

A worker does not have a document and cannot own DOM nodes. Sending an element handle into worker evaluation asks Puppeteer to use a page-only reference in a worker realm.

The snippets use a WebDriver BiDi page with an existing dedicated worker. The fix continues from the worker above.

const worker = page.workers()[0];

await page.setContent(
    '<p id="message">Hello</p>'
);

const message = await page.$("#message");

await worker.evaluate(
    (element) => element.textContent,
    message
);

How to fix

Read the DOM in the page, then pass the text or another plain value to the worker.

const text = await page.$eval(
    "#message",
    (element) => element.textContent
);

const length = await worker.evaluate(
    (value) => value.length,
    text
);

console.log(length);

Things to keep in mind

Public evaluation commonly rejects this earlier as a cross-global handle error. The exact “Cannot adopt DOM nodes” message is an internal worker-adoption guard, not a guaranteed result of every page-to-worker call.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →