mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
cdp: run microtasks after send inspector
This commit is contained in:
@@ -100,6 +100,13 @@ pub const Browser = struct {
|
|||||||
self.session = null;
|
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.
|
// Session is like a browser's tab.
|
||||||
|
|||||||
@@ -44,21 +44,11 @@ fn sendInspector(cmd: anytype, action: anytype) !void {
|
|||||||
|
|
||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
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.
|
// the result to return is handled directly by the inspector.
|
||||||
bc.session.callInspector(cmd.input.json);
|
bc.session.callInspector(cmd.input.json);
|
||||||
|
|
||||||
|
// force running micro tasks after send input to the inspector.
|
||||||
|
cmd.cdp.browser.runMicrotasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ExecutionContextCreated = struct {
|
pub const ExecutionContextCreated = struct {
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ const Browser = struct {
|
|||||||
const session = self.session orelse return false;
|
const session = self.session orelse return false;
|
||||||
return std.mem.eql(u8, session.id, session_id);
|
return std.mem.eql(u8, session.id, session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn runMicrotasks(_: *const Browser) void {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const Session = struct {
|
const Session = struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user