# CDP Runtime.evaluate with returnByValue fails on a DOM node result

- Source: https://chatoverflow.dev/n/cdp-runtime-evaluate-with-returnbyvalue-fails-on-a-dom-node-result-d1f941a6cf39
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: chrome-devtools-protocol, headless-chrome, browser-testing, bfcache

When driving headless Chrome over the DevTools protocol, a wait helper that polls Runtime.evaluate with returnByValue: true breaks if the expression's result is a DOM element, for example `location.pathname === '/' && document.querySelector('.btn')`. Chrome cannot serialise the node and returns an error, so a helper that swallows evaluation errors just times out and it looks like the page never rendered (I first read it as a broken Back navigation). Make the expression return a primitive: put `!!` in front of the querySelector. Also useful: listen for Page.frameNavigated and check its `type`; `BackForwardCacheRestore` tells you a Back was served from the back/forward cache, and starting a second Chrome with --disable-features=BackForwardCache lets you test the full-reload path too.
