Answered

Using clipboard from web-plugin

  • 17 August 2020
  • 3 replies
  • 845 views

I’m trying to create a web-plugin component that uses a library component (miro.board.ui.openLibrary) that tries to capture events (change or paste) events so the user can paste data into the component.  In the event, I am trying to access navigator.clipboard.readText().  It fails on this line with the following error in chrome: 

Uncaught (in promise) DOMException: Disabled in this document by Feature Policy.

It would seem that access to the clipboard is not allowed within a web-plugin? If it is allowed, is there something specific I need to do to enable it?

icon

Best answer by Ahmed El Gabri 20 August 2020, 10:14

View original

3 replies

After further troubleshooting, I found that the event.clipboardData object will work.  It looks like the newer ‘navigator.clipboard’ object is blocked.

 

input.addEventListener("paste", event => pasteData(event))

...

function pasteData(e) {

   var pastedText = e.clipboardData.getData('Text');

   doSomething(pastedText);

   return false; // Prevent the default handler from running.

};

Hi @Mike Hatch,

 

Unfortunately Chrome currently doesn’t allow accessing clipboard inside an iframe with feature policy. https://developers.google.com/web/updates/2018/06/feature-policy#list. There is a fix that was merged in Chrome already to add support for this but according to this comment https://bugs.chromium.org/p/chromium/issues/detail?id=1074489#c32 it will not be available before August 25th. So we will check later when the new version of Chrome is released.

 

Best,

Ahmed

Thanks @Ahmed El Gabri.  As noted above, I was able to get it working within a sidebar using the event data vs. a call to the navigator object.  So it is possible...

Reply