Skip to content

Commit 93f51de

Browse files
committed
Allign error detection
1 parent 97c6ac0 commit 93f51de

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/cdp/domains/dom.zig

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,25 @@ fn rectToQuad(rect: DOMRect) Quad {
267267
}
268268

269269
fn scrollIntoViewIfNeeded(cmd: anytype) !void {
270-
_ = (try cmd.params(struct {
270+
const params = (try cmd.params(struct {
271271
nodeId: ?Node.Id = null,
272272
backendNodeId: ?u32 = null,
273273
objectId: ?[]const u8 = null,
274274
rect: ?DOMRect = null,
275275
})) orelse return error.InvalidParams;
276+
// Only 1 of nodeId, backendNodeId, objectId may be set, but chrome just takes the first non-null
276277

277-
// Only 1 of nodeId, backendNodeId, objectId may be set, but we don't want to error unnecessarily
278-
// TBD what do other browsers do in this user error sceneario?
278+
// We retrieve the node to at least check if it exists and is valid.
279+
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
280+
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
279281

280-
// Since element.scrollIntoViewIfNeeded is a no-op we do not bother retrieving the node.
281-
// This however also means we also do not error in case the node is not found.
282+
const node_type = parser.nodeType(node._node) catch return error.InvalidNode;
283+
switch (node_type) {
284+
.element => {},
285+
.document => {},
286+
.text => {},
287+
else => return error.NodeDoesNotHaveGeometry,
288+
}
282289

283290
return cmd.sendResult(null, .{});
284291
}
@@ -296,6 +303,8 @@ fn getNode(arena: Allocator, browser_context: anytype, node_id: ?Node.Id, backen
296303
return error.MissingParams;
297304
}
298305

306+
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getContentQuads
307+
// Related to: https://drafts.csswg.org/cssom-view/#the-geometryutils-interface
299308
fn getContentQuads(cmd: anytype) !void {
300309
const params = (try cmd.params(struct {
301310
nodeId: ?Node.Id = null,
@@ -307,8 +316,15 @@ fn getContentQuads(cmd: anytype) !void {
307316

308317
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
309318

319+
// TODO likely if the following CSS properties are set the quads should be empty
320+
// visibility: hidden
321+
// display: none
322+
310323
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
311-
// TBD should the funcion work on nodes that are not elements, but may have geometry like Window?
324+
// TODO implement for document or text
325+
// Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
326+
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
327+
// Elements like SVGElement may have multiple quads.
312328

313329
const element = parser.nodeToElement(node._node);
314330
const rect = try bc.session.page.?.state.renderer.getRect(element);

0 commit comments

Comments
 (0)