Skip to content

fix(frontend): Firefox clipboard fallback for permalink copying#9879

Draft
Nish2005karsh wants to merge 1 commit into
marimo-team:mainfrom
Nish2005karsh:fix-firefox-clipboard-3912
Draft

fix(frontend): Firefox clipboard fallback for permalink copying#9879
Nish2005karsh wants to merge 1 commit into
marimo-team:mainfrom
Nish2005karsh:fix-firefox-clipboard-3912

Conversation

@Nish2005karsh

@Nish2005karsh Nish2005karsh commented Jun 13, 2026

Copy link
Copy Markdown

This pull request was authored by a coding agent.

Fixes #3912

Problem

"Create permalink" / "Create WebAssembly link" doesn't copy to the clipboard in Firefox. The permalink actions in useNotebookActions.tsx await readCode() before calling copyToClipboard(url). In Firefox, the await consumes the transient user activation that navigator.clipboard.writeText() requires, so the write rejects and nothing reaches the clipboard.

Fix

Fixed centrally in the shared copyToClipboard util (every copy in the app routes through it, so this covers permalinks and all other copy actions). New fallback chain:

  1. navigator.clipboard.write for rich text/HTML — unchanged
  2. navigator.clipboard.writeText — modern path
  3. New: hidden textarea + document.execCommand("copy") — has laxer user-activation requirements, so it succeeds in Firefox after an await. The user's existing selection is saved and restored so it's invisible.
  4. window.prompt — last resort (unchanged behavior, now reached less often)

document.execCommand("copy") is already used elsewhere in the codebase (cell-context-menu.tsx, vscode-bindings.ts), so this is consistent with existing patterns.

Tests

Added 4 unit tests to copy.test.ts covering: writeText success, the Firefox writeText-rejects → execCommand fallback, the no-navigator.clipboard case, and falling through to window.prompt when both fail.

  • pnpm --filter @marimo-team/frontend test src/utils/__tests__/copy.test.ts → 14 passed
  • typecheck, oxlint, and oxfmt clean for the changed files

Review in cubic

Closes marimo-team#3912

The "Create WebAssembly link"/molab permalink actions await an async
readCode() before copying the resulting URL. In Firefox this consumes the
transient user activation that navigator.clipboard.writeText requires, so
the write rejects and the permalink is never copied.

Add a hidden-textarea + document.execCommand("copy") fallback to the shared
copyToClipboard util, which has laxer user-activation requirements and so
succeeds after an await. Because every copy in the app routes through this
util, the fix applies to permalinks and all other copy actions. The user's
existing selection is preserved and restored, and window.prompt remains as
the last resort.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jun 13, 2026 6:19pm

Request Review

@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

Create permalink doesn't copy to clipboard in firefox

1 participant