Skip to content

Copy Page action fails on browsers without ClipboardItem #13

@schickling

Description

@schickling

Summary

When using the copy action in Firefox (and other browsers that do not expose window.ClipboardItem), clicking Copy page throws a runtime error and nothing is written to the clipboard.

Steps to reproduce

  1. Install starlight-contextual-menu@0.1.3 in a Starlight site.
  2. Open the site in Firefox 130 (or Safari 18).
  3. Click the Copy page button.

Expected behaviour

The page markdown should be copied to the clipboard.

Actual behaviour

The browser console shows:

Failed to copy Markdown: ReferenceError: ClipboardItem is not defined
    at Object.action (contextual-menu.js:18:31)

Context

The injected script creates a new ClipboardItem(...) without checking whether the API exists. Firefox only supports navigator.clipboard.writeText, so the constructor reference throws. A small feature-detection guard (falling back to writeText) would fix the issue.

Suggested fix

Guard the Copy Page handler with:

if (typeof window.ClipboardItem === "undefined") {
  await navigator.clipboard.writeText(markdown)
  return
}

Happy to help test a patch—thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions