apache / cordova-plugin-inappbrowser

Apache Cordova InAppBrowser Plugin

Home Page:https://cordova.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ref.executeScript can't write clipboard

limingzxf opened this issue · comments

function legacyCopy(value) {
alert(66)
const ta = document.createElement('textarea')
ta.value = value ?? ''
ta.style.position = 'absolute'
ta.style.opacity = '0'
document.body.appendChild(ta)
ta.select()
document.execCommand('copy')
ta.remove()
alert(76)
}
legacyCopy("res")
will alert 66 and 76,but not write to clipboard

async function copyTextToClipboard(textToCopy) {
try {
if (navigator?.clipboard?.writeText) {
await navigator.clipboard.writeText(textToCopy);
}
} catch (err) {
alert(err);
}
}
copyTextToClipboard(res)

will alert "write persimmon denied"

i try
const { clipboard } = cordova.plugins;
clipboard.copy("res");
still not working

I want to use webview to inject js, but it seems impossible
it have many bug

This doesn't appear to be a bug with the in-app browser plugin.

Using executeScript to trigger paste commands, either via the deprecated execCommand or the newer Clipboard API likely won't work because they need to be triggered from a trusted user event. E.g. the code needs to run as part of a user-initiated device on the DOM. Injected javascript is not considered a secure source in the DOM context.

thanks,
I would use another injection tool, or give up