@@ -20,6 +20,7 @@ const std = @import("std");
2020const parser = @import ("netsurf" );
2121const Node = @import ("../Node.zig" );
2222const css = @import ("../../dom/css.zig" );
23+ const dom_node = @import ("../../dom/node.zig" );
2324
2425pub fn processMessage (cmd : anytype ) ! void {
2526 const action = std .meta .stringToEnum (enum {
@@ -28,6 +29,7 @@ pub fn processMessage(cmd: anytype) !void {
2829 performSearch ,
2930 getSearchResults ,
3031 discardSearchResults ,
32+ resolveNode ,
3133 }, cmd .input .action ) orelse return error .UnknownMethod ;
3234
3335 switch (action ) {
@@ -36,6 +38,7 @@ pub fn processMessage(cmd: anytype) !void {
3638 .performSearch = > return performSearch (cmd ),
3739 .getSearchResults = > return getSearchResults (cmd ),
3840 .discardSearchResults = > return discardSearchResults (cmd ),
41+ .resolveNode = > return resolveNode (cmd ),
3942 }
4043}
4144
@@ -115,6 +118,36 @@ fn getSearchResults(cmd: anytype) !void {
115118 return cmd .sendResult (.{ .nodeIds = node_ids [params .fromIndex .. params .toIndex ] }, .{});
116119}
117120
121+ fn resolveNode (cmd : anytype ) ! void {
122+ const params = (try cmd .params (struct {
123+ nodeId : ? Node.Id = null ,
124+ backendNodeId : ? u32 = null ,
125+ objectGroup : ? []const u8 = null ,
126+ executionContextId : ? u32 = null ,
127+ })) orelse return error .InvalidParams ;
128+ if (params .nodeId == null or params .backendNodeId != null or params .executionContextId != null ) {
129+ return error .NotYetImplementedParams ;
130+ }
131+
132+ const bc = cmd .browser_context orelse return error .BrowserContextNotLoaded ;
133+ const node = bc .node_registry .lookup_by_id .get (params .nodeId .? ) orelse return error .UnknownNode ;
134+
135+ // node._node is a *parser.Node we need this to be able to find its most derived type e.g. Node -> Element -> HTMLElement
136+ // So we use the Node.Union when retrieve the value from the environment
137+ const jsValue = try bc .session .env .findOrAddValue (try dom_node .Node .toInterface (node ._node ));
138+ const remoteObject = try bc .session .inspector .getRemoteObject (& bc .session .env , jsValue , params .objectGroup orelse "" );
139+ defer remoteObject .deinit ();
140+
141+ const arena = cmd .arena ;
142+ return cmd .sendResult (.{ .object = .{
143+ .type = try remoteObject .getType (arena ),
144+ .subtype = try remoteObject .getSubtype (arena ),
145+ .className = try remoteObject .getClassName (arena ),
146+ .description = try remoteObject .getDescription (arena ),
147+ .objectId = try remoteObject .getObjectId (arena ),
148+ } }, .{});
149+ }
150+
118151const testing = @import ("../testing.zig" );
119152
120153test "cdp.dom: getSearchResults unknown search id" {
0 commit comments