Skip to content

daemon runJSInCurrentTab: js command fails with -1728 when front window has zero tabs (sister concern from #85) #87

Description

@kiki830621

Problem

daemon 的 runJSInCurrentTab template(PreCompiledScripts.swift:105-115):

tell application "Safari"
    do JavaScript "{{JS_SOURCE}}" in current tab of front window
end tell

— Source: PreCompiledScripts.swift:111-115

current tab of front window 在 front window 為 0-tab 時不存在 → AppleScript raise -1728js(及走 daemon JS path 的命令)失敗。此 template 沒有 try guard

Type

bug

Reproduction

  1. Safari front window 為 0-tab(剛開的 profile 空視窗 / Cmd+N 空白視窗)
  2. safari-browser js "document.title"(走 daemon JS path)
  3. line 113 current tab of front window raise -1728 → 命令失敗

Expected

front window 為 0-tab 時,JS 命令應給出可理解的錯誤(例如 "front window has no tabs — open a tab or use --url/--window"),或 fallback 到有 tab 的 window,而非吐 raw -1728

Actual

raw AppleScript -1728

Root Cause

in current tab of front window 假設 front window 有 current tab。0-tab front window 無 current tab,且此 daemon template 沒有 try guard。

Suggested fix

  • 明確指定有 tab 的 target,或在 front window 0-tab 時給明確錯誤訊息
  • 兩條 path 應一致:in-process 的 front-window current tab 存取(SafariBridge.swift:2962-2965)已包 try;daemon 這條(PreCompiledScripts.swift:113)沒有

Relation to #85

同根(0-tab / current tab 缺 guard),本 issue 是 daemon JS path 的版本。#85 修 in-process listAllWindows 枚舉路徑;本 issue 修 daemon JS template 的 front-window 假設。


Source: surfaced during /idd-diagnose #85 sister concern surfacing (Step 3.6)


Current Status

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions