Skip to content

feat(extension): reuse existing options page tab when opening settings - #515

Merged
ujiro99 merged 3 commits into
dev-1.4.0from
feat/reuse-options-page-tab
Oct 23, 2026
Merged

ujiro99 merged 3 commits into
dev-1.4.0from
feat/reuse-options-page-tab

Conversation

@ujiro99

@ujiro99 ujiro99 commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

概要

設定画面を開く操作で、すでに設定画面のタブが開いていれば重複して開かず、既存のタブを再利用するようにしました。

変更内容

  • src/services/chrome.ts に openOptionPage(path?) を追加
    • 全ウィンドウから設定画面のタブを探し、見つかればアクティブにしてウィンドウも前面に出す
    • クエリ付きのパス(?addPageRule=... など)が渡された場合は、既存タブをそのURLへ遷移させる
    • 見つからなければ新規タブで開く
  • 以下の箇所を openOptionPage() に置き換え
    • 拡張機能アイコンのクリック(chrome.action.onClicked)
    • ServiceWorkerCommand.openOption
    • ページルールの追加・編集(ServiceWorkerCommand.addPageRule)
    • Hub からのコマンド編集(handleEditCommand)
  • handleEditCommand では、既存タブを再利用した場合は編集完了後もそのタブを閉じない(新規に作成したタブのみ閉じる)

補足

  • クエリ付きで既存タブを開き直すとページが再読み込みされるため、設定画面に保存前の入力があると失われる可能性があります

確認

  • tsc --noEmit が通ること
  • Extension のユニットテスト(全件)が通ること
  • ブラウザ上で、設定画面を開いた状態で以下を行い、既存タブが再利用されること
    • 拡張機能アイコンのクリック
    • ページルールの追加・編集
    • Hub からのコマンド編集(編集後に既存タブが閉じないこと)

🤖 Generated with Claude Code

ujiro99 and others added 2 commits October 22, 2026 14:09
Use chrome.runtime.openOptionsPage() for the action icon click and the
openOption command so an already opened options page in the current
window is activated instead of opening a duplicate tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…terized URLs

Replace chrome.runtime.openOptionsPage() with an openOptionPage() helper
that searches all windows for an existing options page tab, and use it
for the action icon, the openOption command, adding/editing page rules,
and editing a command from the Hub. When a query is given, the existing
tab is navigated to it so the target dialog opens.

When the Hub edit reuses an existing tab, the tab is kept open after the
edit instead of being closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ujiro99
ujiro99 marked this pull request as ready for review October 23, 2026 02:06
- Match options page tabs that are still loading via pendingUrl
- Prefer the options page tab in the last focused window
- Do not reuse the edit tab of a cancelled Hub edit session
- Catch errors from openOptionPage() in the service worker
- Update stale comments on reading location.search
- Await the opened tab in tests instead of a fixed number of ticks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

レビュー結果

設定画面タブの再利用という目的に対して、実装は素直で読みやすく、テストも追加されています。全体として良い PR です。以下、指摘と提案です。

指摘(軽微〜中)

  1. packages/extension/src/services/chrome.ts の openOptionPage(startsWith(optionPageUrl) 判定)
    前方一致なので、将来 options_page.html.bak のような別パスができた場合に誤検知します。new URL(...) で origin + pathname を比較する方が堅牢です。

  2. ハッシュのみが異なる場合の挙動(chrome.ts の props.url 設定部)
    ハッシュだけが異なる URL への tabs.update は再読み込みなしのフラグメント遷移になります。現状は ?editCommand=... などクエリが付くため問題ありませんが、判定が path !== OPTION_PAGE_PATH なので「クエリの有無」という意図とずれています。コメントや条件を揃えると明確です。

  3. 保存前の入力が失われる点(PR 説明にも記載あり)
    ページルール追加・Hub 編集で既存タブを再読み込みするため、未保存の編集内容が警告なく消えます。将来的には再読み込みせず runtime.sendMessage でパラメータを渡す方式も検討に値します。

  4. packages/extension/src/services/hub/serviceWorker.ts の handleEditCommand
    再利用時は editTabId を設定しないため、編集完了後にタブが閉じない設計は妥当です。再利用タブがユーザー操作で閉じられた場合も、EDIT_CONNECT_TIMEOUT_MS でセッションが回収されることを確認してください。

  5. packages/extension/src/service_worker.ts の Object.assign 整形変更
    機能と無関係なフォーマット変更が混ざっています。害はありませんが、分離が望ましいです。

良い点

  • excludeTabId でキャンセル済みセッションのタブを再利用しない配慮(EC-05)。
  • pendingUrl で読み込み中のタブも検出(COP-05)。
  • すべての呼び出し元で .catch によりエラー処理。
  • 最後にフォーカスされたウィンドウを優先する挙動もテスト済み。

テスト

  • openOptionPage の主要分岐は網羅されています。
  • 追加提案: windows.update が失敗した場合や tabs.update が undefined を返す場合(tab ?? existing)のテスト。

セキュリティ上の懸念は見当たりません(対象は拡張機能自身の URL のみ)。

@ujiro99
ujiro99 merged commit dc6c2c0 into dev-1.4.0 Oct 23, 2026
2 checks passed
@ujiro99
ujiro99 deleted the feat/reuse-options-page-tab branch October 23, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant