question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async clipboard api (navigator.clipboard) does not have permissions in nw frame

See original GitHub issue

NWJS Version : 0.35.5 Operating System : Linux/All

Expected behavior

The async clipboard api navigator.clipboard.readText() should work without having to do anything extra to get permission in NW frames.

Optional: As a bonus it would be great if you can use navigator.clipboard.readText without it being connected to a UI event.

Actual behavior

Nothing happens, promise never resolves. It is the same behavior if you used normal browser and just never clicked the permission prompt to block or allow access to the clipboard.

How to reproduce

The following should output the clipboard buffer to console after clicking on the button:

var el = document.createElement('input');
el.type='button';
el.value='click me';
el.onclick = function() {
    navigator.clipboard.readText().then((text) => { console.log(text); }, (err) => { console.error('Failed:', err); });
};
document.getElementsByTagName('body')[0].appendChild(el);

Also this example async clipboard api page should work: https://googlechrome.github.io/samples/async-clipboard/

As a bonus it would be great if you can use navigator.clipboard.readText without it being connected to a UI event (press button). In that case just running:

navigator.clipboard.readText().then((text) => { console.log(text); }, (err) => { console.error('Failed:', err); });

Should output the clipboard to console. Although it would be very nice, it isn’t part of the API spec.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bluthencommented, Jan 21, 2019

Ok. Thanks. But I even have node-remote for all URLs. These are pages I can import node modules, but can’t use the async clipboard api.

*://*/*

0reactions
bluthencommented, Feb 3, 2020

Seems like this is working now for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unblocking clipboard access - web.dev
The Async Clipboard API addresses these issues, providing a well-defined permissions model that doesn't block the page. The Async Clipboard ...
Read more >
Clipboard.read() - Web APIs - MDN Web Docs
A Promise that resolves with an array of ClipboardItem objects containing the clipboard's contents. The promise is rejected if permission to ...
Read more >
Async Clipboard API: Accessing the clipboard using JavaScript
Checking clipboard access permissions. We can check if we have permission to access the clipboard using the Permissions API: await navigator.
Read more >
Error When Copying to Clipboard From Iframe - Hello Dev World
Long answer short security. If there were no permissions needed for writing to a clipboard a page could add malicious content to you...
Read more >
navigator.clipboard is undefined - google chrome
More on the clipboard API can be found here. Chrome Version: 68.0.3440.106. I'm sure this was working at some point, but no longer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found