diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html
index 50cc37b..1d887fe 100644
--- a/sidepanel/sidepanel.html
+++ b/sidepanel/sidepanel.html
@@ -17,7 +17,7 @@
-
+
diff --git a/sidepanel/sidepanel.js b/sidepanel/sidepanel.js
index 753f808..1f507c7 100644
--- a/sidepanel/sidepanel.js
+++ b/sidepanel/sidepanel.js
@@ -497,10 +497,31 @@ document.getElementById('open-list').addEventListener('click', () => {
// ---------------------------------------------------------------------------
// Init
// ---------------------------------------------------------------------------
+
+// Chrome does not always grant focus to the panel document the moment it
+// opens (notably via the keyboard shortcut), so the focus() call in
+// loadNoteForTab can silently fail. Retry briefly after init, stopping as
+// soon as the editor has focus or the user interacts with anything else.
+function retryEditorFocus() {
+ let attempts = 0;
+ const timer = setInterval(() => {
+ attempts++;
+ if (document.activeElement === editor || attempts > 10) {
+ clearInterval(timer);
+ return;
+ }
+ editor.focus();
+ }, 100);
+ const stop = () => clearInterval(timer);
+ window.addEventListener('pointerdown', stop, { capture: true, once: true });
+ window.addEventListener('keydown', stop, { capture: true, once: true });
+}
+
(async function init() {
const tabId = await resolveHostTab();
if (tabId != null) {
await loadNoteForTab(tabId);
+ retryEditorFocus();
} else {
pageTitleEl.textContent = 'Side Notes';
updateStatus('Could not detect active tab');