Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create instance of ClipboardEvent in Chrome?

I need to programmatically create a ClipboardEvent instance in Chrome.

But when I run the constructor:

new ClipboardEvent("paste", {dataType: "text/plain", data: "some data"})

It throws the following error:

Uncaught TypeError: Illegal constructor

The constructor works as intended in Firefox.

Checked MDN and W3C spec and they don't mention anything about it being illegal to create instances of ClipboardEvent.

Is it possible to create an instance of ClipboardEvent in Chrome in any other way? I prefer to not mock a custom ClipboardEvent when one exists.

Update 2018-07-17: Using the ClipboardEvent seems to work in Chrome 69.

like image 871
Robin Andersson Avatar asked Mar 04 '15 17:03

Robin Andersson


1 Answers

Unfortunately, it's not. This is from http://caniuse.com/#feat=clipboard

Partial support in IE refers using a non-standard method of interacting with the clipboard. For other browsers it refers to not supporting the ClipboardEvent constructor.

enter image description here

Unfortunately, the only browser that properly supports the Clipboard API is FireFox (since 22). All other browsers (if it supports Clipboard API at all), will not support the ClipbordEvent constructor.

like image 58
Jack Avatar answered Sep 19 '22 16:09

Jack