Skip to content

Commit c5776f0

Browse files
Merge pull request #231 from lightpanda-io/browser-wait
browser: extract loop wait
2 parents 11f7fc4 + 7a6d929 commit c5776f0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/browser/browser.zig

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,24 @@ pub const Page = struct {
197197
try Dump.writeHTML(self.doc.?, out);
198198
}
199199

200+
pub fn wait(self: *Page) !void {
201+
const alloc = self.arena.allocator();
202+
var res = try self.session.env.waitTryCatch(alloc);
203+
defer res.deinit(alloc);
204+
205+
if (res.success) {
206+
log.debug("wait: {s}", .{res.result});
207+
} else {
208+
if (builtin.mode == .Debug and res.stack != null) {
209+
log.info("wait: {s}", .{res.stack.?});
210+
} else {
211+
log.info("wait: {s}", .{res.result});
212+
}
213+
}
214+
215+
return;
216+
}
217+
200218
// spec reference: https://html.spec.whatwg.org/#document-lifecycle
201219
pub fn navigate(self: *Page, uri: []const u8) !void {
202220
const alloc = self.arena.allocator();
@@ -448,8 +466,7 @@ pub const Page = struct {
448466
const opt_text = try parser.nodeTextContent(parser.elementToNode(e));
449467
if (opt_text) |text| {
450468
// TODO handle charset attribute
451-
var res = jsruntime.JSResult{};
452-
try self.session.env.run(alloc, text, "", &res, null);
469+
var res = try self.session.env.execTryCatch(alloc, text, "");
453470
defer res.deinit(alloc);
454471

455472
if (res.success) {
@@ -498,8 +515,7 @@ pub const Page = struct {
498515
// check no body
499516
if (fetchres.body == null) return FetchError.NoBody;
500517

501-
var res = jsruntime.JSResult{};
502-
try self.session.env.run(alloc, fetchres.body.?, src, &res, null);
518+
var res = try self.session.env.execTryCatch(alloc, fetchres.body.?, src);
503519
defer res.deinit(alloc);
504520

505521
if (res.success) {

src/main_get.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub fn main() !void {
8989
try page.navigate(url);
9090
defer page.end();
9191

92+
try page.wait();
93+
9294
if (dump) {
9395
try page.dump(std.io.getStdOut());
9496
}

0 commit comments

Comments
 (0)