I’m trying to implement native sharing using Capacitor’s share plugging, but it’s not working either on the web or on native devices, below is my code :
import { Share } from "@capacitor/share";
async function shareContent() {
const isShareContent = await Share.canShare();
console.log(isShareContent);
if (isShareContent.value) {
await Share.share({
title: "See cool stuff",
text: "Really awesome thing you need to see right now",
url: "https://web.myapp.com/",
dialogTitle: "Share with buddies",
});
}
}
The code looks right. I am using it in Vue as well.
A couple of tips. You should use Share.canShare() to make sure sharing is available.
Second, you should wrap it in a try /catch as if the user cancels the share, it throws a JS error. If I remember correctly, the error doesn’t cause any issues, I just didn’t like seeing it in the console.
Thanks for your suggestion. I already use the Share.canShare() to ensure that the platform is capable of sharing, on the web browser, it returns false on the console obviously. Not so sure how I can test on mobile devices.
What you says it’s true but I’m not sure it’s a viable option… You want to be able to use a share feature on more browsers than those you mentioned. It depends on the requirements.