Clipboard API Events

93 views
Skip to first unread message

Mahmoud Galal

unread,
Sep 2, 2023, 1:44:38 PM9/2/23
to v8-dev
Hello 

I wonder why there's no Event that fire, on a clipboard changes?

the existed events, are available only on copy, and paste

most buttons that copy content in the clipboard, uses the writeText() method

which doesn't fire any of the available events

so how about having a event about the changed that happen to the clipboard, on a writeText, or even just onChange

and if it possible, how can I contribute to impelement it ?

guest271314

unread,
Sep 3, 2023, 12:55:46 PM9/3/23
to v8-dev
You can do something like

navigator.clipboard.addEventListener('writetext', (e) => {
  console.log(e);
});
var text = '123';
addEventListener('click', async () => {
  await navigator.clipboard.writeText(text)
    .then(() => navigator.clipboard.dispatchEvent(new CustomEvent('writetext', {detail:{textWrittenToClipboard:text}}))
    ).catch(console.error);
}, {once: true});

Jakob Kummerow

unread,
Sep 4, 2023, 5:35:03 AM9/4/23
to v8-...@googlegroups.com
Note that all of this is out of scope on this mailing list. As far as V8 is concerned, typeof navigator === "undefined".


--

Mahmoud Galal

unread,
Sep 4, 2023, 11:11:17 AM9/4/23
to v8-dev
So where I could look for that ?

guest271314

unread,
Sep 4, 2023, 11:14:57 AM9/4/23
to v8-...@googlegroups.com
I think Jakob Kummerow is saying this particular board doesn't want to deal with this question. 

Since navigator.clipboard inherits from Event you can attach an event listener directly to the object and fire your own custom event.

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/5040f9cc-fc55-4e01-aa79-53ad27f0739cn%40googlegroups.com.

Mahmoud Galal

unread,
Sep 5, 2023, 6:28:49 PM9/5/23
to v8-dev
How can I do that for Clipboard change, as I don't have access to this

guest271314

unread,
Sep 7, 2023, 9:07:20 AM9/7/23
to v8-dev
You will have to implement firing the custom change event yourself. You can do that at the browser of OS level.
Reply all
Reply to author
Forward
0 new messages