Skip to content

[BUG] [GSSoC'26] Share Link silently fails for non-ASCII text overlays -- btoa() throws on Unicode characters #1111

@anshul23102

Description

@anshul23102

Bug description

The "Copy Link" button in src/components/VideoEditor.tsx uses btoa() to base64-encode the current recipe. btoa() only accepts Latin-1 characters (code points 0-255). When a user adds a text overlay containing any character outside that range — Chinese, Japanese, Arabic, Hindi, emoji, or even common accented characters like ü, é, ñbtoa() throws an uncaught DOMException. The button silently does nothing: no link is copied, no error is shown, the UI does not update.

Root cause

src/components/VideoEditor.tsx, handleCopyLink (lines ~252-261):

const handleCopyLink = () => {
  if (typeof window === "undefined") return;
  const encoded = btoa(JSON.stringify(recipe));  // throws if recipe has Unicode
  const url = new URL(window.location.href);
  url.searchParams.set("settings", encoded);
  history.replaceState(null, "", url.toString());
  navigator.clipboard.writeText(url.toString()).then(() => {
    setShareCopied(true);
    setTimeout(() => setShareCopied(false), 2000);
  });
  // No catch — DOMException is unhandled
};

JSON.stringify(recipe) includes the full recipe object, which contains recipe.textOverlays[].text — user-typed text. Any multi-byte character causes btoa() to throw:

DOMException: Failed to execute 'btoa' on 'Window':
The string to be encoded contains characters outside of the Latin1 range.

Since there is no try/catch, navigator.clipboard.writeText is never reached, setShareCopied(true) is never called, and the button gives no feedback.

Steps to reproduce

  1. Upload any video
  2. Open the "Text Overlay" section and type any non-ASCII text (e.g. 你好, مرحبا, こんにちは, ñoño, 🎬)
  3. Click "Copy Link" in the sidebar
  4. Nothing happens — no feedback, no link copied, no error

Expected behavior

The link should be generated and copied regardless of what characters are in the text overlay. The button should show "Copied!" feedback as it does with ASCII-only text.

Actual behavior

btoa() throws silently. The button does nothing. No error is visible to the user.

Suggested fix

Encode the JSON using encodeURIComponent before btoa to safely handle the full Unicode range:

// Encode (in handleCopyLink)
const encoded = btoa(unescape(encodeURIComponent(JSON.stringify(recipe))));

And update decodeRecipe to decode symmetrically:

// Decode (in decodeRecipe)
const decoded = JSON.parse(decodeURIComponent(escape(atob(encoded))));

Alternatively, use the TextEncoder API with a base64url approach, which is the modern standard.

The fix should also add a try/catch around the clipboard write for browsers that block clipboard access outside user gestures.

Browser and OS info

  • Reproducible in all browsers (Chrome, Firefox, Safari)
  • Only triggers when text overlays contain characters with code points > 255

Video format (if relevant)

  • Not video-specific; any video reproduces this once a non-ASCII text overlay is added

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions