Add --wait-selector, --wait-script and --wait-script-file options to fetch

These new optional parameter run AFTER --wait-until, allowing the (imo) useful
combination of `--wait-until load --wait-script "report.complete === true"`.
However, if `--wait-until` IS NOT specified but `--wait-selector/script` IS,
then there is no default wait and it'll just check the selector/script. If
neither `--wait-selector` or `--wait-script/--wait-script-file` are specified
 then  `--wait-until` continues to default to `done`.

These waiters were added to the Runner, and the existing Action.waitForSelector
now uses the runner's version. Selector querying has been split into distinct
parse and query functions, so that we can parse once, and query on every tick.

We could potentially optimize --wait-script to compile the script once and call
it on each tick, but we'd have to detect page navigation to recompile the script
in the new context. Something I'd rather optimize separately.
This commit is contained in:
Karl Seguin
2026-03-31 12:22:51 +08:00
parent 47afdc003a
commit ab6c63b24b
14 changed files with 290 additions and 90 deletions

View File

@@ -1179,7 +1179,7 @@ test "AXNode: writer" {
var registry = Node.Registry.init(testing.allocator);
defer registry.deinit();
var page = try testing.pageTest("cdp/dom3.html");
var page = try testing.pageTest("cdp/dom3.html", .{});
defer page._session.removePage();
var doc = page.window._document;

View File

@@ -343,7 +343,7 @@ test "cdp Node: Registry register" {
try testing.expectEqual(0, registry.lookup_by_id.count());
try testing.expectEqual(0, registry.lookup_by_node.count());
var page = try testing.pageTest("cdp/registry1.html");
var page = try testing.pageTest("cdp/registry1.html", .{});
defer page._session.removePage();
var doc = page.window._document;
@@ -400,7 +400,7 @@ test "cdp Node: search list" {
}
{
var page = try testing.pageTest("cdp/registry2.html");
var page = try testing.pageTest("cdp/registry2.html", .{});
defer page._session.removePage();
var doc = page.window._document;
@@ -440,7 +440,7 @@ test "cdp Node: Writer" {
var registry = Registry.init(testing.allocator);
defer registry.deinit();
var page = try testing.pageTest("cdp/registry3.html");
var page = try testing.pageTest("cdp/registry3.html", .{});
defer page._session.removePage();
var doc = page.window._document;