[Bug]: `DOM.requestNode` returns `nodeId=0`
See original GitHub issueBug description
Steps to reproduce the problem:
- Visit a page with an element with id=demo_id and open a CDP session
- Obtain the
RemoteObjectId
of the node, usingRuntime.evaluate
with{expression:"demo_id"}
- Request the corresponding
NodeId
usingDOM.requestNode
- Issue: Get back
nodeId=0
…? To compare: execute the following in the experimental Protocol Monitor console in the Chromium devtools: {"command":"Runtime.evaluate", "parameters":{"expression":"demo_id"}}
{"command":"DOM.requestNode", "parameters":{"objectId":"<RemoteObjectId just obtained>"}}
- Get back the actual nonzero
NodeId
(If you execute this in the same browser as the previous steps, you will notice that that theRemoteObjectId
obtained in step 5 is the same as in step 2. However, if you execute step 6 without executing step 5 you will get backCould 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:
- Created a year ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
(Chromium bug is now at https://crbug.com/1374241. Your workaround using
DOM.getDocument
seems to work, even withdepth=0
)@OrKoN Ok thanks, that might be the cause, I guess I’ll report it there then. I need the
NodeId
forDOMDebugger.setDOMBreakpoint
btw.