How to detect if browser has Share API


#1

I tried using

if (navigator.share) {
// we can use web share!
} else {
// provide a fallback here
}

but it gives error using ionic build --prod

TQ


#2

I use:

Share.share(options).catch(err => {
  console.log(err);
  // provide fallback here
});

which uses the Web Share API if available (see https://github.com/ionic-team/capacitor/blob/master/core/src/web/share.ts) and you can provide a fallback inside the catch.


#3

Thank you. Got it working now.