Skip to content

fix(extension): コンテキストメニュー・ショートカットからサイドパネルを開けない問題を修正 - #583

Draft
ujiro99 wants to merge 3 commits into
dev-1.5.0from
fix/context-menu-side-panel-363
Draft

ujiro99 wants to merge 3 commits into
dev-1.5.0from
fix/context-menu-side-panel-363

Conversation

@ujiro99

@ujiro99 ujiro99 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

概要

#363 の対応。ブラウザネイティブのコンテキストメニューやキーボードショートカットから、サイドパネルを使うコマンド(通常・AI Prompt・Page Action のサイドパネルモード)を実行するとサイドパネルが開かない問題を修正。

原因

コマンドは SW → content script → SW の経路で実行されるため、chrome.sidePanel.open() を呼ぶ時点でユーザージェスチャーが失われていた。ページ上のクリックと違い、ブラウザ UI の操作ではページにユーザーアクティベーションが付かない。

対応

  • src/services/sidePanelPreOpen.ts を追加。イベントハンドラ内で await より前に、空白ページ(url なしの relay ページ)でサイドパネルを先に開く
  • ActionHelper.openSidePanel / chrome.openSidePanel: 事前オープン済みのタブでは open() を呼ばず setOptions でページだけ設定
  • コンテキストメニュー: サイドパネル系コマンドのメニュー ID に sidePanel: プレフィックスを付け、SW のコールドスタート時も同期的に判定
  • ショートカット: サイドパネル系ショートカット ID をメモリにキャッシュ(設定変更で更新)
  • コマンドが実行されなかった場合(content script がない、選択なしで「何もしない」など)は即座に、それ以外で30秒以内にページが設定されなかった場合はパネルを閉じる
    • content script は executeAction を受け付けたら true を返すようにし、送信側が失敗を判別できるようにした
  • すでにサイドパネルが開いているタブでは空ページに置き換えず、キャンセル時も閉じない(onClosed 対応ブラウザのみ。非対応では開閉状態を正しく追えないため従来通り事前オープンする)
  • 閉じる処理の待機中(約1秒)に同じタブで再度開かれた場合は、遅れて届く無効化をスキップする
  • ショートカット設定(STORAGE_KEY.SHORTCUTS)の変更でもキャッシュを更新

既知の制約

  • ショートカットで SW が起動した直後は、キャッシュ読み込みの await 後に開こうとするため、Chrome の挙動次第で開けない可能性がある(従来と同じ失敗になるだけで副作用なし)
  • 目的のページが表示されるまで、空白のパネルが一瞬表示される

確認項目

  • コンテキストメニューから SIDE_PANEL / AI Prompt / Page Action(サイドパネルモード)を実行して開く
  • SW を停止した状態からコンテキストメニューで実行して開く
  • ショートカットで上記3種類を実行して開く(SW 起動中・停止中)
  • 選択なしで「何もしない」設定のショートカットを押すとパネルが閉じる
  • サイドパネル表示中に上記を行っても、表示中の内容が消えない
  • 拡張機能の更新後、リロードしていないタブでコンテキストメニューから実行しても空パネルが残らない
  • オプション画面でショートカットの割り当てを変えた直後でも開く
  • Vivaldi でも同様に動作する
  • ポップアップメニューから実行するときの既存動作に影響がない

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pd1sH2SVL35AWHUxzVCAqk

ujiro99 and others added 3 commits November 23, 2026 19:31
A command started from the native context menu or a keyboard shortcut is
run by the content script, so chrome.sidePanel.open() was called after the
user gesture was lost. Open the side panel with a blank page synchronously
in the event handler, and let the later openSidePanel request only set the
page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pd1sH2SVL35AWHUxzVCAqk
- Refresh the side panel shortcut cache when the shortcuts are changed.
- Do not let a stale open() failure clear a newer pre-opened state.
- Move test-only exports to __test and fix test names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pd1sH2SVL35AWHUxzVCAqk
- Respond to executeAction, so the sender can tell a tab without the
  content script and close the pre-opened side panel at once.
- Keep an already open side panel instead of replacing it with a blank
  page, and do not close it when the command does not run.
- Skip the delayed disable of a pre-open close when the side panel of the
  tab is opened again while closing.
- Extend the pre-open timeout to 30 seconds for permission prompts.
- Fix the service worker tests broken by the shortcut storage listener.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pd1sH2SVL35AWHUxzVCAqk

This branch has not been deployed

No deployments
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