Skip to content

Fix: Make clipboard success reporting reliable - #8

Merged
labib2002 merged 1 commit into
mainfrom
fix-clipboard-reporting
Sep 30, 2025
Merged

Fix: Make clipboard success reporting reliable#8
labib2002 merged 1 commit into
mainfrom
fix-clipboard-reporting

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

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.

PR created automatically by Jules for task 16442205392442526423

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.
@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

@labib2002
labib2002 marked this pull request as ready for review September 30, 2025 21:09
@labib2002
labib2002 merged commit 4fd0d65 into main Sep 30, 2025
@labib2002
labib2002 deleted the fix-clipboard-reporting branch September 30, 2025 22:00
labib2002 added a commit that referenced this pull request Jul 10, 2026
Fix: Make clipboard success reporting reliable
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