@@ -20,6 +20,7 @@ const std = @import("std");
20
20
const parser = @import ("netsurf" );
21
21
const Node = @import ("../Node.zig" );
22
22
const css = @import ("../../dom/css.zig" );
23
+ const dom_node = @import ("../../dom/node.zig" );
23
24
24
25
pub fn processMessage (cmd : anytype ) ! void {
25
26
const action = std .meta .stringToEnum (enum {
@@ -28,6 +29,7 @@ pub fn processMessage(cmd: anytype) !void {
28
29
performSearch ,
29
30
getSearchResults ,
30
31
discardSearchResults ,
32
+ resolveNode ,
31
33
}, cmd .input .action ) orelse return error .UnknownMethod ;
32
34
33
35
switch (action ) {
@@ -36,6 +38,7 @@ pub fn processMessage(cmd: anytype) !void {
36
38
.performSearch = > return performSearch (cmd ),
37
39
.getSearchResults = > return getSearchResults (cmd ),
38
40
.discardSearchResults = > return discardSearchResults (cmd ),
41
+ .resolveNode = > return resolveNode (cmd ),
39
42
}
40
43
}
41
44
@@ -115,6 +118,36 @@ fn getSearchResults(cmd: anytype) !void {
115
118
return cmd .sendResult (.{ .nodeIds = node_ids [params .fromIndex .. params .toIndex ] }, .{});
116
119
}
117
120
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
+
118
151
const testing = @import ("../testing.zig" );
119
152
120
153
test "cdp.dom: getSearchResults unknown search id" {
0 commit comments