Skip to content

Commit d1d3b96

Browse files
committed
cdp: run microtasks after send inspector
1 parent 85caa09 commit d1d3b96

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/browser/browser.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ pub const Browser = struct {
103103
self.session = null;
104104
}
105105
}
106+
107+
pub fn runMicrotasks(self: *const Browser) void {
108+
// if no session exists, there is nothing to do.
109+
if (self.session == null) return;
110+
111+
return self.session.?.env.runMicrotasks();
112+
}
106113
};
107114

108115
// Session is like a browser's tab.

src/cdp/runtime.zig

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,11 @@ fn sendInspector(cmd: anytype, action: anytype) !void {
4444

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

47-
// remove awaitPromise true params
48-
// TODO: delete when Promise are correctly handled by zig-js-runtime
49-
if (action == .callFunctionOn or action == .evaluate) {
50-
const json = cmd.input.json;
51-
if (std.mem.indexOf(u8, json, "\"awaitPromise\":true")) |_| {
52-
// +1 because we'll be turning a true -> false
53-
const buf = try cmd.arena.alloc(u8, json.len + 1);
54-
_ = std.mem.replace(u8, json, "\"awaitPromise\":true", "\"awaitPromise\":false", buf);
55-
bc.session.callInspector(buf);
56-
return;
57-
}
58-
}
59-
6047
// the result to return is handled directly by the inspector.
6148
bc.session.callInspector(cmd.input.json);
49+
50+
// force running micro tasks after send input to the inspector.
51+
cmd.cdp.browser.runMicrotasks();
6252
}
6353

6454
pub const ExecutionContextCreated = struct {

src/cdp/testing.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const Browser = struct {
4646
const session = self.session orelse return false;
4747
return std.mem.eql(u8, session.id, session_id);
4848
}
49+
50+
pub fn runMicrotasks(_: *const Browser) void {}
4951
};
5052

5153
const Session = struct {

0 commit comments

Comments
 (0)