Yes, used Britzl’s extension. To make it work in the browsers too, add in the touch event’s callback:
-- native app clipboard copy is handled by the clipboard library
if (clipboard ~= nil) then
clipboard.copy(share_message(self))
else
-- html5 clipboard copy is handled by the "polyfill"
defos.on_interaction(function()
copy_text(self)
end)
end
where copy_text
is a local function:
-- this function is used to copy a given text to the clipboard, on browser builds
local function copy_text(self)
-- check if the current browser supports the clipboard API
local result = html5.run("navigator.clipboard")
if result == "[object Clipboard]" then
-- executes the supplied string as JavaScript inside the browser.
html5.run("clipboard_copy('" .. share_message(self) .. "')")
else
print("Can't access clipboard")
end
end
Now, the last step is to provide the clipboard_copy
function. Add it to the page’s head
tag:
<script type="text/javascript">
async function clipboard_copy(thing_to_copy) {
const result = await navigator.clipboard.writeText(thing_to_copy);
}
</script>