Skip to content

Copy/Cut broken in Firefox: XSLTProcessor failure + invalid clipboard-write permission + custom MIME type rejected #918

Open
logseq/logseq
#13892

Description

@asano69

Search first

  • I searched and no similar issues were found

What Happened?

Copy and Cut operations (via keyboard shortcut and context menu) are broken in Firefox.
No content is written to the clipboard, making Paste a no-op after Copy,
and Cut deletes the selection without saving it to the clipboard.

The following errors appear in the browser console:

  1. XSLTProcessor.importStylesheet() throws NS_ERROR_FAILURE (0x80600001).
    Although Logseq has a parseerror fallback in the XSLT path, the exception
    is uncaught before reaching it.

  2. navigator.permissions.query({ name: 'clipboard-write' }) throws a TypeError
    because Firefox does not recognise 'clipboard-write' as a valid PermissionName.
    This prevents execution from reaching clipboard.write() at all.

  3. Even when (2) is bypassed, clipboard.write() fails with:
    NotAllowedError: Type 'web application/logseq' not supported for write
    because Firefox rejects non-standard MIME types in ClipboardItem.

Firefox has also announced that XSLTProcessor will be removed entirely
in a future release: mozilla/standards-positions#1287

Workaround (paste into the browser console after page load):

(function () {
  // Fix 1: Replace XSLTProcessor with a stub that returns a parseerror document,
  // triggering Logseq's own fallback to the raw HTML string.
  // Also future-proof against Firefox's planned removal of XSLTProcessor.
  window.XSLTProcessor = class {
    importStylesheet() {}
    transformToDocument() {
      return new DOMParser().parseFromString("<parsererror/>", "application/xml");
    }
  };

  // Fix 2: Firefox does not recognise 'clipboard-write' as a valid PermissionName.
  const _permQuery = navigator.permissions.query.bind(navigator.permissions);
  navigator.permissions.query = function (desc) {
    if (desc?.name === "clipboard-write" || desc?.name === "clipboard-read")
      return Promise.resolve({ state: "granted", onchange: null });
    return _permQuery(desc);
  };

  // Fix 3: Firefox rejects custom MIME types in ClipboardItem; fall back to writeText.
  const _write = navigator.clipboard.write.bind(navigator.clipboard);
  const _writeText = navigator.clipboard.writeText.bind(navigator.clipboard);

  navigator.clipboard.write = async function (items) {
    try { return await _write(items); } catch (_) {}

    for (const type of ["text/plain", "text/html"]) {
      for (const item of items) {
        if (!item.types.includes(type)) continue;
        try {
          const text = await item.getType(type).then(b => b.text());
          if (text) return await _writeText(text);
        } catch (_) {}
      }
    }
  };
})();

With this workaround applied, Copy and Cut work correctly (content is written as text/plain).

Reproduce the Bug

  1. Open Logseq DB in Firefox (tested on Firefox 150.0.1).
  2. Open any page that contains blocks.
  3. Select one or more blocks.
  4. Press Ctrl+C (Copy) or use the context menu → Copy.
  5. Open a text editor outside Logseq and press Ctrl+V.

→ Nothing is pasted.

Alternatively:
4. Press Ctrl+X (Cut) or use the context menu → Cut.

→ The selection is deleted from Logseq, but nothing is available to paste.

Console errors observed (in order):

  • Uncaught NS_ERROR_FAILURE at XSLTProcessor.importStylesheet() (utils.js)
  • TypeError: 'clipboard-write' is not a valid value for enumeration PermissionName (util.cljc)

Not reproducible in Chromium-based browsers.

Expected Behavior

Copy should write the selected block content to the system clipboard so that
it can be pasted both inside Logseq and in external applications.

Cut should do the same and additionally remove the selection from the document.

Both operations work correctly in Chromium. Firefox compatibility requires:

  1. Avoiding XSLTProcessor (or guarding against its failure/absence), given
    that Firefox is deprecating and planning to remove it entirely.
  2. Not calling navigator.permissions.query({ name: 'clipboard-write' }),
    which is not a valid permission name in Firefox.
  3. Avoiding non-standard MIME types (e.g. application/logseq) in ClipboardItem,
    and falling back to text/plain or text/html when clipboard.write() fails.

Screenshots

No response

Files

No response

Browser, Desktop or Mobile Platform Information

Firefox 150.0.1
https://test.logseq.com/ (2026-06-04)

Additional Context

No response

Are you willing to submit a PR? If you know how to fix the bug.

  • I'm willing to submit a PR (Thank you!)

Activity

  1. self-assigned this
    on Aug 7, 2026
  2. yuxi-liu-wired commented on Oct 27, 2026

    @yuxi-liu-wired

    Fixed in logseq/logseq#13892 (fix(clipboard): copy, cut and paste keep working when Firefox refuses a clipboard call). Its description has the cause and the test that pins it; it fails on current master and passes with the fix.

  3. added 11 commits that reference this issue on Oct 29, 2026
    618c24d
    2fe87ee
    5c8c398
    13084ef
    888f843
    5335ea5
    b5db827
    31f7dd6
    c30b62d
    835dd73
    803879e
  4. added 17 commits that reference this issue on Nov 11, 2026
    627ce3c
    e027359
    af43076
    a813311
    d29b10b
    68a1c5d
    0f2ce5b
    1c1a812
    d5d1938
    6203050
    bfb3d17
    ac66d48
    8040512
    034b5ff
    7041a89
    a8eb840
    70e160f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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