mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
CDP: simplify AXNode name extraction logic
This commit is contained in:
@@ -760,9 +760,8 @@ pub fn getName(self: AXNode, page: *Page, allocator: std.mem.Allocator) !?[]cons
|
|||||||
var aw: std.Io.Writer.Allocating = .init(allocator);
|
var aw: std.Io.Writer.Allocating = .init(allocator);
|
||||||
defer aw.deinit();
|
defer aw.deinit();
|
||||||
|
|
||||||
// We need to bypass the strict JSON writer used in writeName
|
// writeName expects a std.json.Stringify instance.
|
||||||
// We'll create a dummy writer that just writes to our buffer
|
const TextCaptureWriter = struct {
|
||||||
const DummyWriter = struct {
|
|
||||||
aw: *std.Io.Writer.Allocating,
|
aw: *std.Io.Writer.Allocating,
|
||||||
writer: *std.Io.Writer,
|
writer: *std.Io.Writer,
|
||||||
|
|
||||||
@@ -773,52 +772,27 @@ pub fn getName(self: AXNode, page: *Page, allocator: std.mem.Allocator) !?[]cons
|
|||||||
} else if (comptime std.meta.hasMethod(T, "format")) {
|
} else if (comptime std.meta.hasMethod(T, "format")) {
|
||||||
try std.fmt.format(w.aw.writer, "{s}", .{val});
|
try std.fmt.format(w.aw.writer, "{s}", .{val});
|
||||||
} else {
|
} else {
|
||||||
// Ignore unexpected types to avoid garbage output
|
// Ignore unexpected types (e.g. booleans) to avoid garbage output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn beginWriteRaw(w: @This()) !void {
|
// Mock JSON Stringifier lifecycle methods
|
||||||
_ = w;
|
pub fn beginWriteRaw(_: @This()) !void {}
|
||||||
}
|
pub fn endWriteRaw(_: @This()) void {}
|
||||||
pub fn endWriteRaw(w: @This()) void {
|
pub fn objectField(_: @This(), _: []const u8) !void {}
|
||||||
_ = w;
|
pub fn beginObject(_: @This()) !void {}
|
||||||
}
|
pub fn endObject(_: @This()) !void {}
|
||||||
pub fn writeByte(w: @This(), b: u8) !void {
|
pub fn beginArray(_: @This()) !void {}
|
||||||
try w.aw.writer.writeByte(b);
|
pub fn endArray(_: @This()) !void {}
|
||||||
}
|
|
||||||
pub fn writeAll(w: @This(), s: []const u8) !void {
|
|
||||||
try w.aw.writer.writeAll(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mock object methods
|
|
||||||
pub fn objectField(w: @This(), name: []const u8) !void {
|
|
||||||
_ = w;
|
|
||||||
_ = name;
|
|
||||||
}
|
|
||||||
pub fn beginObject(w: @This()) !void {
|
|
||||||
_ = w;
|
|
||||||
}
|
|
||||||
pub fn endObject(w: @This()) !void {
|
|
||||||
_ = w;
|
|
||||||
}
|
|
||||||
pub fn beginArray(w: @This()) !void {
|
|
||||||
_ = w;
|
|
||||||
}
|
|
||||||
pub fn endArray(w: @This()) !void {
|
|
||||||
_ = w;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const w = DummyWriter{ .aw = &aw, .writer = &aw.writer };
|
const w = TextCaptureWriter{ .aw = &aw, .writer = &aw.writer };
|
||||||
|
|
||||||
const source = try self.writeName(w, page);
|
const source = try self.writeName(w, page);
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
var str = aw.written();
|
// Remove literal quotes inserted by writeString.
|
||||||
// writeString manually injects literal quotes for JSON, we need to strip them
|
const raw_text = std.mem.trim(u8, aw.written(), "\"");
|
||||||
if (str.len >= 2 and str[0] == '"' and str[str.len - 1] == '"') {
|
return try allocator.dupe(u8, raw_text);
|
||||||
str = str[1 .. str.len - 1];
|
|
||||||
}
|
|
||||||
return try allocator.dupe(u8, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user