clipboard-polyfill icon indicating copy to clipboard operation
clipboard-polyfill copied to clipboard

writeText throws exception in chrome within an iframe

Open jasonhieu1905 opened this issue 3 years ago • 3 comments

Scenarios:

  • copy text to clipboard running on Chrome within an iframe using import { writeText } from 'clipboard-polyfill/text'.

Current behaviors:

  • It throws exception 3.

When changing to write api and insert it as a ClipboardItem. It works fine.

write([new ClipboardItem({
                    [ClipboardItemMimeType.TextPlain]: 'some text',
                }])

Do you know what are the different between permissions of 2 api.

Chrome version: Version 95.0.4638.54

jasonhieu1905 avatar Oct 28 '21 03:10 jasonhieu1905

That does sound pretty weird. Do you have an example page I can try to debug?

lgarron avatar Oct 28 '21 05:10 lgarron

something's weird also happens in my product, it only works for write api. you can play around here (notes that I just try with the navigator api)

https://stackblitz.com/edit/js-cnr1ww?file=index.js ( issue for both 2apis)

with the same code if I am running on w3schools, it's working fine.

jasonhieu1905 avatar Oct 28 '21 07:10 jasonhieu1905

something's weird also happens in my product, it only works for write api. you can play around here (notes that I just try with the navigator api)

https://stackblitz.com/edit/js-cnr1ww?file=index.js ( issue for both 2apis)

with the same code if I am running on w3schools, it's working fine.

If I copy your HTML to a local file, navigator.clipboard.writeText('data') seems to work perfectly. (Note that testing inside stackblitz.com is not good way, since that wraps the page in even more frames.)

Do you have another example page that exhibits the issue?

lgarron avatar Nov 07 '21 21:11 lgarron

Could you let me know if v4.0.0-rc3 fixes your issue?

lgarron avatar Jan 05 '23 09:01 lgarron

I'm closing this for now, because the latest build tries more fallbacks for writeText(). Please feel welcome to file a new issue if you still have trouble!

lgarron avatar Jan 07 '23 01:01 lgarron