-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Clipboard doesn't work in a webview #8170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
close with the same fix in #7855 (comment) |
@rogerwang, it did not help: I've rewritten
And clipboard still doesn't work. |
Here is the code I'm using: {
"main": "index.html",
"name": "bug",
"node-main": "--no-experimental-global-navigator",
"webview": {
"partitions": [
{
"name": "trusted*",
"accessible_resources": ["*"]
}
]
}
} <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
html, body, webview {
display: block;
margin: 0; padding: 0; border: 0;
width: 100%; height: 100%;
}
html, body {
overflow: hidden;
}
webview {
position: absolute;
top: 0; left: 0;
}
</style>
</head>
<body>
<webview src="webview.html" partition="persist:trusted" allownw></webview>
</body>
</html> <!DOCTYPE html>
<html>
<body>
<p>Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.</p>
<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>
<script>
function myFunction() {
// Get the text field
var copyText = document.getElementById("myInput");
// Select the text field
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
// Alert the copied text
alert("Copied the text: " + copyText.value);
}
</script>
</body>
</html> |
@rogerwang , your code works with local resources but it doesn't work with remote resources... Why? 😟 |
@rogerwang I've also tested code from issue #7855. Everything works with local resources, but nothing with remote. |
try this with remote urls, which is under different permissions than local extension resources {
"main": "index.html",
"name": "bug",
"node-main": "--no-experimental-global-navigator",
"content_capabilities": {
"matches": [
"https://*.w3schools.com/"
],
"permissions": [
"clipboardRead",
"clipboardWrite"
]
},
"webview": {
"partitions": [
{
"name": "trusted*",
"accessible_resources": ["*"]
}
]
}
} <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
html, body, webview {
display: block;
margin: 0; padding: 0; border: 0;
width: 100%; height: 100%;
}
html, body {
overflow: hidden;
}
webview {
position: absolute;
top: 0; left: 0;
}
</style>
</head>
<body>
<webview src="https://www.w3schools.com/howto/howto_js_copy_clipboard.asp" partition="persist:trusted"></webview>
</body>
</html> |
@rogerwang worked with:
Could you provide more information about param |
It's from the spec of Chrome extension. A NW app is an extension under the hood. |
@rogerwang that's strange because even here I can't find anything. |
Current/Missing Behavior
navigator.clipboard.writeText
doesn't work in webviews. See how to reproduce section for demo.Expected/Proposed Behavior
It should work
Additional Info
How to reproduce
package.json
main.html
Demo opens page with live demostraion of "Copy Text to Clipboard" which perfectly works in browser, but doesn't work in webviews.
The text was updated successfully, but these errors were encountered: