Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ pub const Page = struct {
try Dump.writeHTML(self.doc.?, out);
}

pub fn wait(self: *Page) !void {
const alloc = self.arena.allocator();
var res = try self.session.env.waitTryCatch(alloc);
defer res.deinit(alloc);

if (res.success) {
log.debug("wait: {s}", .{res.result});
} else {
if (builtin.mode == .Debug and res.stack != null) {
log.info("wait: {s}", .{res.stack.?});
} else {
log.info("wait: {s}", .{res.result});
}
}

return;
}

// spec reference: https://html.spec.whatwg.org/#document-lifecycle
pub fn navigate(self: *Page, uri: []const u8) !void {
const alloc = self.arena.allocator();
Expand Down Expand Up @@ -448,8 +466,7 @@ pub const Page = struct {
const opt_text = try parser.nodeTextContent(parser.elementToNode(e));
if (opt_text) |text| {
// TODO handle charset attribute
var res = jsruntime.JSResult{};
try self.session.env.run(alloc, text, "", &res, null);
var res = try self.session.env.execTryCatch(alloc, text, "");
defer res.deinit(alloc);

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

var res = jsruntime.JSResult{};
try self.session.env.run(alloc, fetchres.body.?, src, &res, null);
var res = try self.session.env.execTryCatch(alloc, fetchres.body.?, src);
defer res.deinit(alloc);

if (res.success) {
Expand Down
2 changes: 2 additions & 0 deletions src/main_get.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub fn main() !void {
try page.navigate(url);
defer page.end();

try page.wait();

if (dump) {
try page.dump(std.io.getStdOut());
}
Expand Down