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
9 changes: 8 additions & 1 deletion src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ pub const Browser = struct {
self.session = null;
}
}

pub fn runMicrotasks(self: *const Browser) void {
// if no session exists, there is nothing to do.
if (self.session == null) return;

return self.session.?.env.runMicrotasks();
}
};

// Session is like a browser's tab.
Expand Down Expand Up @@ -237,7 +244,7 @@ pub const Session = struct {
std.debug.assert(self.page != null);

// Reset all existing callbacks.
self.app.loop.reset();
self.app.loop.resetJS();

self.env.stop();
// TODO unload document: https://html.spec.whatwg.org/#unloading-documents
Expand Down
16 changes: 3 additions & 13 deletions src/cdp/runtime.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,11 @@ fn sendInspector(cmd: anytype, action: anytype) !void {

const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;

// remove awaitPromise true params
// TODO: delete when Promise are correctly handled by zig-js-runtime
if (action == .callFunctionOn or action == .evaluate) {
const json = cmd.input.json;
if (std.mem.indexOf(u8, json, "\"awaitPromise\":true")) |_| {
// +1 because we'll be turning a true -> false
const buf = try cmd.arena.alloc(u8, json.len + 1);
_ = std.mem.replace(u8, json, "\"awaitPromise\":true", "\"awaitPromise\":false", buf);
bc.session.callInspector(buf);
return;
}
}

// the result to return is handled directly by the inspector.
bc.session.callInspector(cmd.input.json);

// force running micro tasks after send input to the inspector.
cmd.cdp.browser.runMicrotasks();
}

pub const ExecutionContextCreated = struct {
Expand Down
2 changes: 2 additions & 0 deletions src/cdp/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const Browser = struct {
const session = self.session orelse return false;
return std.mem.eql(u8, session.id, session_id);
}

pub fn runMicrotasks(_: *const Browser) void {}
};

const Session = struct {
Expand Down
2 changes: 1 addition & 1 deletion vendor/zig-js-runtime