Skip to content

Commit 151ff3b

Browse files
committed
cdp: run microtasks after send inspector
1 parent 3a1a582 commit 151ff3b

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
@@ -100,6 +100,13 @@ pub const Browser = struct {
100100
self.session = null;
101101
}
102102
}
103+
104+
pub fn runMicrotasks(self: *const Browser) void {
105+
// if no session exists, there is nothing to do.
106+
if (self.session == null) return;
107+
108+
return self.session.?.env.runMicrotasks();
109+
}
103110
};
104111

105112
// 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
@@ -64,6 +64,8 @@ const Browser = struct {
6464
const session = self.session orelse return false;
6565
return std.mem.eql(u8, session.id, session_id);
6666
}
67+
68+
pub fn runMicrotasks(_: *const Browser) void {}
6769
};
6870

6971
const Session = struct {

0 commit comments

Comments
 (0)