Problem
SafariBridge.swift 的 getWindowIDViaAX(windowIndex:)(line ~2583-2587)用 current tab of window N 來「驗證 window N 是否存在」:
tell application "Safari"
set t to current tab of window N
end tell
— Source: SafariBridge.swift:2581-2587,註解明說用途是 "Validate window N exists"
但 current tab 是 window 存在性的錯誤 proxy:window N 確實存在、只是有 0 tabs 時,current tab of window N 不存在 → AppleScript raise -1728 → 命令被誤報失敗,即使 window N 明明存在。此處沒有 try guard。
Type
bug
Reproduction
- Safari 有一個存在但 0-tab 的 window(假設它是 window index 3)
- 跑一個走 AX window-ID resolution 的命令,例如
safari-browser screenshot --window 3 out.png(screenshot / pdf / 需要 CGWindowID 的路徑都經 getWindowIDViaAX)
- line 2585
current tab of window 3 raise -1728 → 命令失敗
Expected
--window N 指向「存在但 0-tab」的 window 時,存在性驗證應成功(window 存在),不該因為它沒有 current tab 就誤判失敗。
Actual
current tab of window N 對 0-tab window raise -1728,validate 步驟失敗。
Root Cause
用 current tab 當 window 存在性檢查。應改用不依賴 tab 的存在性判斷,例如 if exists window N 或 id of window N(window 有 id 即存在,與 tab 數無關)。
Suggested fix
把 line 2585 換成不碰 tab 的存在性驗證:
tell application "Safari"
if not (exists window N) then error "no such window"
-- 或 set _ to id of window N
end tell
Relation to #85
同根(0-tab window 缺 guard),不同觸發點:#85 是「枚舉所有 window」(listAllWindows) 時撞到任一 0-tab window;本 issue 是「使用者用 --window N 明確指定一個 0-tab window」時走 AX 路徑失敗。建議一併處理,徹底根除「用 current tab 當存在性/枚舉 proxy」的 anti-pattern。
對照(已正確,供範圍界定,不需改)
getFrontWindowID(SafariBridge.swift:2962-2965)的 current tab of front window 已包在 try 內,front window 0-tab 不 crash(降級為 nil name)。
- daemon
enumerateWindows(PreCompiledScripts.swift:81-104)先數 tabCount、完全不碰 current tab,已正確。
Source: surfaced during /idd-diagnose #85 sister concern surfacing (Step 3.6)
Current Status
Problem
SafariBridge.swift的getWindowIDViaAX(windowIndex:)(line ~2583-2587)用current tab of window N來「驗證 window N 是否存在」:但
current tab是 window 存在性的錯誤 proxy:window N 確實存在、只是有 0 tabs 時,current tab of window N不存在 → AppleScript raise-1728→ 命令被誤報失敗,即使 window N 明明存在。此處沒有 try guard。Type
bug
Reproduction
safari-browser screenshot --window 3 out.png(screenshot / pdf / 需要 CGWindowID 的路徑都經getWindowIDViaAX)current tab of window 3raise-1728→ 命令失敗Expected
--window N指向「存在但 0-tab」的 window 時,存在性驗證應成功(window 存在),不該因為它沒有 current tab 就誤判失敗。Actual
current tab of window N對 0-tab window raise-1728,validate 步驟失敗。Root Cause
用
current tab當 window 存在性檢查。應改用不依賴 tab 的存在性判斷,例如if exists window N或id of window N(window 有 id 即存在,與 tab 數無關)。Suggested fix
把 line 2585 換成不碰 tab 的存在性驗證:
Relation to #85
同根(0-tab window 缺 guard),不同觸發點:#85 是「枚舉所有 window」(
listAllWindows) 時撞到任一 0-tab window;本 issue 是「使用者用--window N明確指定一個 0-tab window」時走 AX 路徑失敗。建議一併處理,徹底根除「用current tab當存在性/枚舉 proxy」的 anti-pattern。對照(已正確,供範圍界定,不需改)
getFrontWindowID(SafariBridge.swift:2962-2965)的current tab of front window已包在 try 內,front window 0-tab 不 crash(降級為 nil name)。enumerateWindows(PreCompiledScripts.swift:81-104)先數 tabCount、完全不碰 current tab,已正確。Source: surfaced during /idd-diagnose #85 sister concern surfacing (Step 3.6)
Current Status
idd/cluster-zerotab-guard, isolated worktree); regression tests green, full suite no-regression./idd-verify