Search code examples
javascriptandroidcordovagoogle-chromecordova-plugins

Confused about Web share API and Cordova share plugin


I'm trying to implement a share feature in my Cordova app to let users share their pictures

According to the Chrome dev team they introduced a Web share API directly into Google Chrome. To share something just call:

navigator.share({title: 'Example Page', url: 'https://example.com'});

but as far as I know Cordova also has a plugin, namely cordova-share-plugin

To use this plugin, simply call:

navigator.share(text,title,mimetype)

This is where I get confused. Both the built-in share API and the Cordova plugin have the same method navigator.share(). The expected parameters are different.

If I have installed the cordova share plugin and I call navigator.share() which code get executed? the plugin or the native share API?

It looks like one of my user is unable to share pictures because the call to navigator.share() fails silently. He has Android 8.1.0. All the other users seem to trigger the Cordova plugin when my app calls navigator.share()


Solution

  • That's a pretty old plugin, created when navigator.share was not available in the browser.

    The plugin clobbers navigator.share, so it will use the plugin implementation instead of the browser implementation.