Frontend--backend communication and node IDs

17 views
Skip to first unread message

var...@google.com

unread,
Aug 7, 2017, 1:18:34 PM8/7/17
to Google Chrome Developer Tools
Hey everyone,

I am trying to trigger events in the frontend JavaScript section of the DevTools from the C++ backend, which must pass node references between them. As an example, say I want to walk through the DOM when the content has loaded, and print references to each node in the Console. I'm currently a little unclear as to which IDs should be used for such a purpose. In InspectorDOMAgent, there are references to two kinds of IDs: DOMNodeIds and those stored in document_node_to_id_map_ (backend IDs?). There are references to the second in the frontend, with methods such as DOMModel.pushNodesByBackendIdsToFrontend, so I assume these can be used for communication. However, to construct them, one must call BuildObjectForNode -- this would be all right, but it seems this map is often cleared with DiscardFrontendBindings, meaning the IDs become outdated (for example when I try building them in InspectorDOMAgent::DomContentLoadedEventFired, and then switching from the Console to the Elements panel).

Where is the best place to walk the DOM tree as soon as it is available, and to pass information to JavaScript for use in the interface, without getting a mismatch of the node IDs? What is the relation between the different kind of IDs? If anyone could shed any light on the relationship between the frontend and backend in general, and this area specifically, that would really help! Thank you!
Reply all
Reply to author
Forward
0 new messages