Fix: Make clipboard success reporting reliable - #8
Conversation
This commit fixes a bug where the extension would report a clipboard copy failure even when the operation succeeded. The issue was caused by unreliable message passing between the background script and the offscreen document.
The fix implements a more robust communication flow:
1. **`background.js` Changes:**
- A new `ensureOffscreenReady()` function now pings the offscreen document until it's responsive before any messages are sent.
- The `copyToClipboardViaOffscreen()` function was updated to use this readiness check and now includes a retry mechanism, attempting the copy operation twice before failing.
2. **`offscreen.js` Changes:**
- The `onMessage` listener now correctly returns `true` to handle asynchronous `sendResponse` calls, preventing the message port from closing prematurely.
- A new 'ping' message handler was added to confirm when the document is ready.
- The clipboard logic is wrapped in an async IIFE to ensure `sendResponse` is always called.
- The `document.execCommand('copy')` fallback now properly checks its boolean return value.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. |
Fix: Make clipboard success reporting reliable
This commit fixes a bug where the extension would report a clipboard copy failure even when the operation succeeded. The issue was caused by unreliable message passing between the background script and the offscreen document.
The fix implements a more robust communication flow:
background.jsChanges:ensureOffscreenReady()function now pings the offscreen document until it's responsive before any messages are sent.copyToClipboardViaOffscreen()function was updated to use this readiness check and now includes a retry mechanism, attempting the copy operation twice before failing.offscreen.jsChanges:onMessagelistener now correctly returnstrueto handle asynchronoussendResponsecalls, preventing the message port from closing prematurely.sendResponseis always called.document.execCommand('copy')fallback now properly checks its boolean return value.PR created automatically by Jules for task 16442205392442526423