Commit 57d37ba
committed
fix(commands): observe tabs.query/sendMessage promises in genPrompt path
Mirror the pattern already applied in menus.mjs to the keyboard-command
genPrompt branch in commands.mjs so no step here can surface as an
unhandled promise rejection in the background script:
- Browser.tabs.query() is wrapped in try/catch (it can reject on
permission errors, etc.).
- The resulting tabs[0] is guarded before dereferencing currentTab.id —
contextMenus / commands handlers can fire when no active tab is
resolvable, matching the guard menus.mjs already added.
- Browser.tabs.sendMessage() now has a .catch() that logs and swallows
the rejection. webextension-polyfill sendMessage rejects in normal
extension usage when no content script is listening, when the page is
restricted (chrome://, about:, etc.), or when the content script is
stale after an extension reload.
Same rationale as commit c8bfcf3 for menus.mjs — addresses the Copilot
review on src/background/commands.mjs:33 (PR #963).
Lint, prettier, and the test suite (315 tests) all pass.
Co-Authored-By: Octopus <liyuan851277048@icloud.com>1 parent c8bfcf3 commit 57d37ba
1 file changed
Lines changed: 30 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
42 | 67 | | |
43 | 68 | | |
44 | 69 | | |
| |||
0 commit comments