apache / cordova-plugin-inappbrowser

Apache Cordova InAppBrowser Plugin
https://cordova.apache.org/
Apache License 2.0
1.11k stars 2.14k forks source link

ref.executeScript can't write clipboard #1045

Closed limingzxf closed 4 months ago

limingzxf commented 4 months ago

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

limingzxf commented 4 months ago

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"

limingzxf commented 4 months ago

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

limingzxf commented 4 months ago

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

breautek commented 4 months ago

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.

limingzxf commented 4 months ago

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