BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Copy to Clipboard Error in Firefox

Open luukbox opened this issue 1 year ago • 5 comments

Describe the bug Firefox does not support the async Clipboard API, causing an error when attempting to copy content from the editor.

To Reproduce

  • Open BlockNote using Firefox
  • Attempt to copy any text from the editor
  • Uncaught (in promise) DOMException: Modifications are not allowed for this document in the console

Workaround I noticed that createInternalHTMLSerializer and cleanHTMLToMarkdown aren't actually async. Therefore, it seems like selectedFragmentToHTML could be converted to a synchronous function by removing the call to initializeESMDependencies.

In our environment, I was able to do this and tested it successfully with a custom copyToClipboard extension while disabling the default one.

That said, I'm unsure of the exact circumstances when these dependencies are required, or their purpose, so I'm not certain if this is a universally viable solution.

For anyone interested, here is a StackBlitz example demonstrating the workaround.

luukbox avatar Sep 09 '24 14:09 luukbox

Awesome, thanks for providing your code! We did notice this was an issue when first implementing copy/paste but couldn't find a workaround at the time (hence why e2e tests for copy/paste on Firefox are disabled), so even if it requires tweaking it's great to have a something to reference for a fix.

matthewlipski avatar Sep 09 '24 15:09 matthewlipski

Thanks @luukbox - this workaround works for me. One minor change I needed was to use const editor: typeof schema.BlockNoteEditor as I'm using a custom schema.

Dartoxian avatar Sep 12 '24 08:09 Dartoxian

@Dartoxian I tried the same workaroud, but it does not work for me. Is there anything specific you do to make it work?

I have something like this

const schema = BlockNoteSchema.create({
    inlineContentSpecs: {
      ...defaultInlineContentSpecs,
    },
  });

  const editor: typeof schema.BlockNoteEditor = useCreateBlockNote({
    schema,
    initialContent: initialContent
      ? (JSON.parse(initialContent) as PartialBlock[])
      : undefined,
    uploadFile: uploadImage,
  });

and it still does not work.

Thanks a lot

carlonicora avatar Sep 19 '24 10:09 carlonicora

Sorry, in 0.15.9 that works!

carlonicora avatar Sep 19 '24 10:09 carlonicora

In the end the workaround seems to be working to paste something, but it is still present when trying to copy from it

carlonicora avatar Sep 19 '24 12:09 carlonicora