question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: `DOM.requestNode` returns `nodeId=0`

See original GitHub issue

Bug description

Steps to reproduce the problem:

  1. Visit a page with an element with id=demo_id and open a CDP session
  2. Obtain the RemoteObjectId of the node, using Runtime.evaluate with {expression:"demo_id"}
  3. Request the corresponding NodeId using DOM.requestNode
  4. Issue: Get back nodeId=0…? To compare: execute the following in the experimental Protocol Monitor console in the Chromium devtools:
  5. {"command":"Runtime.evaluate", "parameters":{"expression":"demo_id"}}
  6. {"command":"DOM.requestNode", "parameters":{"objectId":"<RemoteObjectId just obtained>"}}
  7. Get back the actual nonzero NodeId (If you execute this in the same browser as the previous steps, you will notice that that the RemoteObjectId obtained in step 5 is the same as in step 2. However, if you execute step 6 without executing step 5 you will get back Could not find object with given id. Not sure if this is by CDP design?)

This may well be an upstream issue, but I’m not sure what causes it to work fine in the devtools and not via Puppeteer.

Script:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({headless: false});
const page    = await browser.newPage();
await page.goto('data:text/html,' + encodeURIComponent('<input id=demo_id />'));

const cdp = await page.target().createCDPSession();
await cdp.send('Runtime.enable');
await cdp.send('DOM.enable');
const {result: {objectId}} = await cdp.send('Runtime.evaluate', {expression: 'demo_id'});
console.log(objectId);  // Correct id
const {nodeId} = await cdp.send('DOM.requestNode', {objectId});
console.log(nodeId);  // 0 ??

Puppeteer version

18.2.1

Node.js version

18.9.0

npm version

8.19.2

What operating system are you seeing the problem on?

Windows

Relevant log output

3462418028677997700.3.1
0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
stevenwdvcommented, Oct 13, 2022

(Chromium bug is now at https://crbug.com/1374241. Your workaround using DOM.getDocument seems to work, even with depth=0)

0reactions
stevenwdvcommented, Oct 10, 2022

@OrKoN Ok thanks, that might be the cause, I guess I’ll report it there then. I need the NodeId for DOMDebugger.setDOMBreakpoint btw.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get nodeIds of elements within iframe using chrome dev tools ...
Found the answer in this gist async function findElementInIframe(DOM, iframeSelector, elementSelector) { const doc = await DOM.
Read more >
DOM.requestNode
MethodDOM.getContainerForNodeexperimental#. Returns the query container of the given node based on container query conditions: containerName, physical, ...
Read more >
cdp - Go Packages
Context, FrameID) error // GetRoot returns the root document node for the top level ... requestNode" CommandDOMPushNodeByPathToFrontend MethodType = "DOM.
Read more >
DOM.querySelector inside shadowDom fail to retrieve nodeId
querySelector () function returns nodeId=0. I actually don't know how to exercise the CDP with this function from within devtools.
Read more >
DOM domain - Chrome DevTools Protocol - GitHub Pages
Chrome DevTools Protocol - version tot - DOM domain. ... Note that iframe owner elements will return corresponding document elements as ... requestNode....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found