From 7d61a7aad3d572da4011b2b1813d542977058913 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:22:49 +0000 Subject: [PATCH] CLI: a tab Ardia lists without an address mid-navigation stays the session's Ardia's Target.getTargets can report a page with url "" for a few milliseconds while it navigates (seen 23-120 ms on Ardia 0.2.49, macOS, and in headless Chromium 156). refreshTargets only keeps targets whose URL has a page scheme, so it forgot the session's tab and with it the ownership: the next tab failed with tab_not_found, and when the target came back at its new URL the session no longer owned it and couldn't close it. A page target already known keeps its last row while its URL is empty; a page first seen without an address is still left out. The tab_blank_url_kept flag is set on a command during which a known tab was listed without an address; watch its rate in cli_command. Closes ardia-browser/ardia#4665 --- plugins/cli/plugin.json | 2 +- plugins/cli/ts/src/browse/metrics.ts | 2 +- plugins/cli/ts/src/browse/state/state.ts | 9 ++++++- plugins/cli/ts/src/browse/tables.ts | 2 +- plugins/cli/ts/src/command-metrics.ts | 1 + plugins/cli/ts/tests/m3/tabs-nav.test.ts | 32 ++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/plugins/cli/plugin.json b/plugins/cli/plugin.json index e459ce0f..2d840097 100644 --- a/plugins/cli/plugin.json +++ b/plugins/cli/plugin.json @@ -69,7 +69,7 @@ "title": "The ardia command", "items": [ "Each command's name (like history or browse snapshot), its exit and error codes, the names of the options it was given (never their values) and, for a batch, which step failed: its number and command name. For ardia computer, the error code says which setup step failed (driver not installed, a permission CuaDriver.app is missing, its background service not starting, bad arguments, a failed tool, or that it was interrupted or its output was closed), never the app, window, text or arguments involved", - "How long it took, step by step (starting up, starting its helper, connecting to Ardia, finding the tab, the command itself, waiting for the page to settle), plus counts and sizes: browser calls, steps in a batch, how many coding agents the install gave the agent skill to or skipped, the length of a page snapshot and of the output, how many requests an action sent, how many reading tabs it had to open again, how many site menus a read printed as one line and how many characters they held, and whether the output was cut short, the input humanized, it gave up waiting for its helper, it set a viewport size, it reloaded a crashed page or Ardia refused it a tab. Times, counts and yes or no only", + "How long it took, step by step (starting up, starting its helper, connecting to Ardia, finding the tab, the command itself, waiting for the page to settle), plus counts and sizes: browser calls, steps in a batch, how many coding agents the install gave the agent skill to or skipped, the length of a page snapshot and of the output, how many requests an action sent, how many reading tabs it had to open again, how many site menus a read printed as one line and how many characters they held, and whether the output was cut short, the input humanized, it gave up waiting for its helper, it set a viewport size, it reloaded a crashed page, Ardia refused it a tab, or Ardia listed a tab without an address for a moment. Times, counts and yes or no only", "For scripts, REPL and MCP sessions: run and call counts, auto-closed or detached tabs, inline images shown, child frames and masked fields in a snapshot, and whether positioned or mouse clicks, native tab diagnostics or native tab input were used. Counts and yes or no only", "Its version, whether it's a release or test build, and this Mac's install ID", "After a crash: the error's type, and its message only when it's one of a fixed list (like “division by zero”); never the stack trace", diff --git a/plugins/cli/ts/src/browse/metrics.ts b/plugins/cli/ts/src/browse/metrics.ts index 445e115a..60b4b79c 100644 --- a/plugins/cli/ts/src/browse/metrics.ts +++ b/plugins/cli/ts/src/browse/metrics.ts @@ -46,7 +46,7 @@ export const FLAGS = new Set([ "script_eval_alias", "script_command_line_split", "script_page_world_hint", "attach_refused", "open_read", "covered_close_ref", "script_timeout_state_shown", "download_fetched_again", "page_busy_fast_fail", "session_busy_on_stuck_tab", "navigation_site_silent", "tab_kept_awake", "viewport_set", "crashed_reloaded", "network_disable_unconfirmed", "reattached_after_detach", "earlier_requests_ignored", "renderer_exit_kept_session", - "setup_restored", "setup_restore_failed", "offscreen_handoff_rolled_back", "setup_session_dropped", "tab_close_interrupted", "tab_readopted_after_restart", "dialog_dismissed_after_failure", "selector_nth", "output_saved", "waited_for_element", "saved_to_file", "batch_line_saved", + "setup_restored", "setup_restore_failed", "offscreen_handoff_rolled_back", "setup_session_dropped", "tab_close_interrupted", "tab_readopted_after_restart", "tab_blank_url_kept", "dialog_dismissed_after_failure", "selector_nth", "output_saved", "waited_for_element", "saved_to_file", "batch_line_saved", "script_state_kept", "saved_as_csv", "script_timeout_read_hint", "click_scroll_locked", "open_still_loading", "focused_inner_field", "stale_ref_after_navigation", "clicked_label_of_hidden_input", "waited_for_box_to_settle", "frame_cross_process_box", "screenshot_unchanged", "route_enable_undone", "script_queued_behind_busy", "navigation_dropped_hint", "navigation_https_only_hint", "eval_timed_out", "read_queued_beside", diff --git a/plugins/cli/ts/src/browse/state/state.ts b/plugins/cli/ts/src/browse/state/state.ts index 029d2e24..930190a5 100644 --- a/plugins/cli/ts/src/browse/state/state.ts +++ b/plugins/cli/ts/src/browse/state/state.ts @@ -409,7 +409,14 @@ export class State extends Refs implements temptabs.TempTabState { const takenAt = wallSeconds(); const raw = (await (this.browser as Browser).send("Target.getTargets"))["targetInfos"]; const infos = (Array.isArray(raw) ? raw : []).map(record); - const pages = infos.filter(isPageInfo); + const known = this.targetInfos; + const pages = infos.flatMap((info) => { + if (isPageInfo(info)) return [info]; + const before = info["type"] === "page" && info["url"] === "" ? known.get(String(info["targetId"])) : undefined; + if (before === undefined) return []; + flag("tab_blank_url_kept", true); + return [{ ...info, url: before["url"], title: info["title"] || before["title"] }]; + }); this.targetInfos = new Map(pages.map((info) => [String(info["targetId"]), info])); for (const targetId of [...this.pages.keys(), ...(this.current ? [this.current] : [])]) { if (!this.targetInfos.has(targetId)) this.forgetTarget(targetId); diff --git a/plugins/cli/ts/src/browse/tables.ts b/plugins/cli/ts/src/browse/tables.ts index 36135a9f..d4ba50bc 100644 --- a/plugins/cli/ts/src/browse/tables.ts +++ b/plugins/cli/ts/src/browse/tables.ts @@ -12,7 +12,7 @@ export const MUTATING: readonly string[] = ["auth", "back", "batch", "cdp", "che export const TAKES_OUT: readonly string[] = ["eval", "get", "read", "repl", "script", "snapshot"]; export const AS_TEXT: readonly string[] = ["get", "snapshot"]; export const TASK_COMMANDS: readonly string[] = ["back", "batch", "check", "click", "dblclick", "download", "drag", "edit-cell", "eval", "fill", "fill-otp", "find", "form", "forward", "here", "hover", "keyboard", "open", "press", "query", "read", "read-urls", "reload", "script", "scroll", "select", "type", "uncheck", "upload"]; -export const METRIC_FLAGS: readonly string[] = ["attach_refused", "batch_line_saved", "batch_ref_ambiguous", "batch_ref_healed", "batch_ref_missing", "batch_ref_not_followed", "batch_saved", "change_run_choices", "change_text", "click_recentered", "click_scroll_locked", "clicked_label_of_hidden_input", "clicked_visible_content", "consent_dismissed", "covered_close_ref", "crashed_reloaded", "daemon_answer_timed_out", "daemon_spawned", "dialog_dismissed_after_failure", "did_you_mean", "dom_click_behind_modal", "dom_click_fallback", "dom_click_waited_for_modal", "dom_snapshot_refused", "dom_snapshot_used", "download_fetched_again", "drag_list_position", "drag_side_given", "earlier_requests_ignored", "element_rehomed", "eval_isolated_reference_error", "eval_main_world", "eval_selectors_quoted", "eval_timed_out", "field_label_fallback", "fill_cleared_beside_chrome", "fill_inserted_text", "fill_no_reaction_hint", "fill_picked_option", "find_closest_names", "find_closest_ref", "find_is", "flow_drifted", "flow_hint_shown", "flow_run_page", "flow_saved", "flow_shaped", "focused_inner_field", "followed_redrawn_ref", "followed_ref_after_reload", "form", "frame_cross_process_box", "frame_point_unconfirmed", "guessed_syntax", "help_in_daemon", "here", "here_read", "humanize", "input_confirmed_by_text", "input_in_inner_frame", "input_lost_drag", "input_lost_keys", "input_lost_pointer", "input_lost_text", "input_lost_wheel", "input_mouse_events_cancelled", "logpoint_source_mapped", "menu_closed_for_click", "modal_dismissed", "names_clipped", "navigation_dropped_hint", "navigation_https_only_hint", "navigation_site_silent", "network_disable_unconfirmed", "network_reloaded", "offscreen_handoff_rolled_back", "oopif_attach_refused", "open_here", "open_moved_tab", "open_read", "open_report", "open_still_loading", "output_saved", "output_truncated", "page_busy_fast_fail", "perf_crux", "permission_granted", "popup_dismissed", "press_targeted", "query", "query_fields", "queued_behind_script", "read_beside_busy", "read_binary_saved", "read_bot_check", "read_data", "read_data_shaped", "read_empty_page", "read_frame_text", "read_links_from_url", "read_matched", "read_oopif_frames", "read_partial_page", "read_pdf", "read_queued_beside", "read_scope_empty", "read_scope_shown", "read_scroll_guessed", "read_scroll_waited_at_end", "read_scrolled", "read_urls", "read_urls_deadline", "read_virtualized_grid", "read_waited_for_content", "read_waited_for_requests", "reattached_after_detach", "reconnected_after_idle", "remedy_shown", "renderer_exit_kept_session", "route_enable_undone", "saved_as_csv", "saved_to_file", "screenshot_unchanged", "script_command_line_split", "script_eval_alias", "script_eval_args", "script_frame_eval", "script_frames_listed", "script_memory_limit", "script_missing_api", "script_page_world_hint", "script_queued_behind_busy", "script_runner_crashed", "script_runner_unconfined", "script_runner_warm", "script_sandbox_hint", "script_selector_eval", "script_state_kept", "script_state_kept_on_interrupt", "script_steps_shown", "script_timeout_read_hint", "script_timeout_state_shown", "select_opened_list", "select_retyped", "select_word_match", "selector_in_shadow_root", "selector_nth", "session_busy_on_stuck_tab", "settle_ignored_background", "setup_restore_failed", "setup_restored", "setup_session_dropped", "snapshot_boxless_skipped", "snapshot_budget_trimmed", "snapshot_closed_shadow", "snapshot_diff", "snapshot_diff_full", "snapshot_disabled_folded", "snapshot_document_changed", "snapshot_dom_depth_retry", "snapshot_find", "snapshot_hidden_text_dropped", "snapshot_lean_trimmed", "snapshot_modal_scoped", "snapshot_oopif_frames", "snapshot_paired", "snapshot_paired_unstable", "snapshot_repeat_labels", "stale_ref_after_navigation", "stale_ref_after_open", "tab_close_interrupted", "tab_kept_awake", "tab_readopted_after_restart", "unsettled", "viewport_set", "waited_for_box_to_settle", "waited_for_element", "waited_for_enabled", "waited_for_reaction"]; +export const METRIC_FLAGS: readonly string[] = ["attach_refused", "batch_line_saved", "batch_ref_ambiguous", "batch_ref_healed", "batch_ref_missing", "batch_ref_not_followed", "batch_saved", "change_run_choices", "change_text", "click_recentered", "click_scroll_locked", "clicked_label_of_hidden_input", "clicked_visible_content", "consent_dismissed", "covered_close_ref", "crashed_reloaded", "daemon_answer_timed_out", "daemon_spawned", "dialog_dismissed_after_failure", "did_you_mean", "dom_click_behind_modal", "dom_click_fallback", "dom_click_waited_for_modal", "dom_snapshot_refused", "dom_snapshot_used", "download_fetched_again", "drag_list_position", "drag_side_given", "earlier_requests_ignored", "element_rehomed", "eval_isolated_reference_error", "eval_main_world", "eval_selectors_quoted", "eval_timed_out", "field_label_fallback", "fill_cleared_beside_chrome", "fill_inserted_text", "fill_no_reaction_hint", "fill_picked_option", "find_closest_names", "find_closest_ref", "find_is", "flow_drifted", "flow_hint_shown", "flow_run_page", "flow_saved", "flow_shaped", "focused_inner_field", "followed_redrawn_ref", "followed_ref_after_reload", "form", "frame_cross_process_box", "frame_point_unconfirmed", "guessed_syntax", "help_in_daemon", "here", "here_read", "humanize", "input_confirmed_by_text", "input_in_inner_frame", "input_lost_drag", "input_lost_keys", "input_lost_pointer", "input_lost_text", "input_lost_wheel", "input_mouse_events_cancelled", "logpoint_source_mapped", "menu_closed_for_click", "modal_dismissed", "names_clipped", "navigation_dropped_hint", "navigation_https_only_hint", "navigation_site_silent", "network_disable_unconfirmed", "network_reloaded", "offscreen_handoff_rolled_back", "oopif_attach_refused", "open_here", "open_moved_tab", "open_read", "open_report", "open_still_loading", "output_saved", "output_truncated", "page_busy_fast_fail", "perf_crux", "permission_granted", "popup_dismissed", "press_targeted", "query", "query_fields", "queued_behind_script", "read_beside_busy", "read_binary_saved", "read_bot_check", "read_data", "read_data_shaped", "read_empty_page", "read_frame_text", "read_links_from_url", "read_matched", "read_oopif_frames", "read_partial_page", "read_pdf", "read_queued_beside", "read_scope_empty", "read_scope_shown", "read_scroll_guessed", "read_scroll_waited_at_end", "read_scrolled", "read_urls", "read_urls_deadline", "read_virtualized_grid", "read_waited_for_content", "read_waited_for_requests", "reattached_after_detach", "reconnected_after_idle", "remedy_shown", "renderer_exit_kept_session", "route_enable_undone", "saved_as_csv", "saved_to_file", "screenshot_unchanged", "script_command_line_split", "script_eval_alias", "script_eval_args", "script_frame_eval", "script_frames_listed", "script_memory_limit", "script_missing_api", "script_page_world_hint", "script_queued_behind_busy", "script_runner_crashed", "script_runner_unconfined", "script_runner_warm", "script_sandbox_hint", "script_selector_eval", "script_state_kept", "script_state_kept_on_interrupt", "script_steps_shown", "script_timeout_read_hint", "script_timeout_state_shown", "select_opened_list", "select_retyped", "select_word_match", "selector_in_shadow_root", "selector_nth", "session_busy_on_stuck_tab", "settle_ignored_background", "setup_restore_failed", "setup_restored", "setup_session_dropped", "snapshot_boxless_skipped", "snapshot_budget_trimmed", "snapshot_closed_shadow", "snapshot_diff", "snapshot_diff_full", "snapshot_disabled_folded", "snapshot_document_changed", "snapshot_dom_depth_retry", "snapshot_find", "snapshot_hidden_text_dropped", "snapshot_lean_trimmed", "snapshot_modal_scoped", "snapshot_oopif_frames", "snapshot_paired", "snapshot_paired_unstable", "snapshot_repeat_labels", "stale_ref_after_navigation", "stale_ref_after_open", "tab_blank_url_kept", "tab_close_interrupted", "tab_kept_awake", "tab_readopted_after_restart", "unsettled", "viewport_set", "waited_for_box_to_settle", "waited_for_element", "waited_for_enabled", "waited_for_reaction"]; export const METRIC_DURATIONS: readonly string[] = ["action_ms", "attach_ms", "cdp_ms_total", "connect_ms", "daemon_start_ms", "eval_ms", "settle_ms", "snapshot_build_ms", "startup_ms", "total_ms"]; export const METRIC_COUNTS: readonly string[] = ["batch_lines_compacted", "batch_lines_held", "batch_refs_healed", "batch_steps", "cdp_calls", "cell_edits", "change_text_chars", "failed_step_index", "flow_items", "flow_params", "flow_requests_kept", "form_fields", "network_writes_count", "output_chars", "query_rows", "read_data_blocks", "read_nav_chars_hidden", "read_nav_hidden", "read_pages", "read_rows", "read_tabs_reopened", "read_urls_count", "read_urls_failed", "script_calls", "script_concurrent_peak", "script_receipts_skipped", "skills_installed", "skills_skipped", "snapshot_chars", "snapshot_find_matches", "snapshot_lean_lines", "snapshot_lines_dropped", "snapshot_new_lines", "snapshot_nodes", "snapshot_oopif_count"]; export const METRIC_MAX_MS = 3600000; diff --git a/plugins/cli/ts/src/command-metrics.ts b/plugins/cli/ts/src/command-metrics.ts index f854a012..328e03f0 100644 --- a/plugins/cli/ts/src/command-metrics.ts +++ b/plugins/cli/ts/src/command-metrics.ts @@ -68,6 +68,7 @@ export const TS_ONLY_FLAGS: readonly string[] = [ "stale_ref_after_open", "tab_close_interrupted", "tab_readopted_after_restart", + "tab_blank_url_kept", "drag_interception_unavailable", "drag_synthetic", "edit_cell", diff --git a/plugins/cli/ts/tests/m3/tabs-nav.test.ts b/plugins/cli/ts/tests/m3/tabs-nav.test.ts index 876670b7..eef32590 100644 --- a/plugins/cli/ts/tests/m3/tabs-nav.test.ts +++ b/plugins/cli/ts/tests/m3/tabs-nav.test.ts @@ -251,6 +251,38 @@ describe("tabs this session opens are closed through the registry", () => { }); }); +describe("a tab Ardia lists without an address while it navigates", () => { + function listing(url: () => string, extra: Record[] = []): FakeBrowser { + return new FakeBrowser((method) => + method === "Target.getTargets" ? { targetInfos: [{ targetId: "TARGET", type: "page", url: url(), title: "" }, ...extra] } : undefined, + ); + } + + test("a pinned session still finds its own tab by target id, and keeps it", async () => { + let url = ""; + const state = stateWith(listing(() => url)); + state.pinTab = true; + state.pinnedTarget = "TARGET"; + state.current = "TARGET"; + state.opened.add("TARGET"); + state.created.add("TARGET"); + await state.page("TARGET"); + const result = await dispatch(ctxOf(state, "tab"), "tab", ["TARGET"]); + expect((result.data as Record)["targetId"]).toBe("TARGET"); + expect(state.opened.has("TARGET")).toBe(true); + expect(state.describeTabs()).toMatchObject([{ targetId: "TARGET", url: "http://127.0.0.1/page.html", openedBySession: true, openedBy: "s" }]); + url = "https://example.com/"; + await state.refreshTargets(); + expect(state.describeTabs()).toMatchObject([{ targetId: "TARGET", url: "https://example.com/", openedBySession: true, openedBy: "s" }]); + }); + + test("a page first seen without an address is still left out", async () => { + const state = stateWith(listing(() => "https://example.com/", [{ targetId: "NEW", type: "page", url: "", title: "" }])); + await state.refreshTargets(); + expect([...state.targetInfos.keys()]).toEqual(["TARGET"]); + }); +}); + describe("navigation", () => { for (const [command, argv, what] of [ ["back", [], "go back in"],