Merge pull request #1292 from lightpanda-io/nikneym/script-execution-changes

Run microtasks after each script execution
This commit is contained in:
Karl Seguin
2025-12-29 18:42:03 +08:00
committed by GitHub
2 changed files with 8 additions and 12 deletions

View File

@@ -945,16 +945,6 @@ fn printWaitAnalysis(self: *Page) void {
} }
} }
pub fn tick(self: *Page) void {
if (comptime IS_DEBUG) {
log.debug(.page, "tick", .{});
}
_ = self.scheduler.run() catch |err| {
log.err(.page, "tick", .{ .err = err });
};
self.js.runMicrotasks();
}
pub fn isGoingAway(self: *const Page) bool { pub fn isGoingAway(self: *const Page) bool {
return self._queued_navigation != null; return self._queued_navigation != null;
} }

View File

@@ -38,7 +38,7 @@ const ScriptManager = @This();
page: *Page, page: *Page,
// used to prevent recursive evalutaion // used to prevent recursive evaluation
is_evaluating: bool, is_evaluating: bool,
// Only once this is true can deferred scripts be run // Only once this is true can deferred scripts be run
@@ -803,7 +803,13 @@ pub const Script = struct {
log.debug(.browser, "executed script", .{ .src = url, .success = success, .on_load = script_element._on_load != null }); log.debug(.browser, "executed script", .{ .src = url, .success = success, .on_load = script_element._on_load != null });
} }
defer page.tick(); defer {
// We should run microtasks even if script execution fails.
page.js.runMicrotasks();
_ = page.scheduler.run() catch |err| {
log.err(.page, "scheduler", .{ .err = err });
};
}
if (success) { if (success) {
self.executeCallback("load", script_element._on_load, page); self.executeCallback("load", script_element._on_load, page);