Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox with ClipboardItem enabled copies [object Promise] #90

Closed
silverwind opened this issue May 17, 2023 · 6 comments
Closed

Firefox with ClipboardItem enabled copies [object Promise] #90

silverwind opened this issue May 17, 2023 · 6 comments

Comments

@silverwind
Copy link

silverwind commented May 17, 2023

To reproduce:

  • Open latest Firefox
  • Set dom.events.asyncClipboard.clipboardItem in about:config
  • Open the application, click Copy SVG
  • It copies the string [object Promise]

I'm not sure where this goes wrong, but I suspect it has something to do with the user agent sniffing. I'm using this same API in this module, so I think it is operational and the bug is from this app code, not from Firefox.

@silverwind silverwind changed the title Firefox with ClipboardItem API just copies [object Promise] Firefox with ClipboardItem enabled copies [object Promise] May 17, 2023
@tomayac
Copy link
Owner

tomayac commented May 18, 2023

This is the relevant code:

copyButton.addEventListener('click', async () => {
. What operating system does this happen on?

@silverwind
Copy link
Author

silverwind commented May 18, 2023

MacOS, window.ClipboardItem does exist with the about:config preference enabled. So I think it ends in this branch:

await navigator.clipboard.write([
  new ClipboardItem({
    'text/plain': new Promise(async (resolve) => {
      resolve(new Blob([svg], { type: 'text/plain' }));
    }),
  }),
]);

@tomayac
Copy link
Owner

tomayac commented May 18, 2023

Thanks for the report. I will take a look soon.

@silverwind
Copy link
Author

I think the likely fix will be to remove the Promise wrapping. I tested the API with non-promise and Safari copied it fine. The fact that it works with Promise in Safari while not in Firefox is likely an implementation difference between the two.

@tomayac
Copy link
Owner

tomayac commented May 26, 2023

Fixed via 4a22344. Thanks for reporting!

@tomayac tomayac closed this as completed May 26, 2023
@silverwind
Copy link
Author

Thanks, confirmed working!

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

No branches or pull requests

2 participants