Web Share API: Google’s exclusive tool for sharing on social networks

The Web Share API, written by a developer named Matt Giuca in the Chrome team, gives Android developers the ability to enable sharing in Android apps with the help of this API.

How to use Web Share API

In this API, the object that is sent must have at least one of the text or url properties, for example:

if (navigator.share) {
  navigator.share({
      title: 'Web Fundamentals',
      text: 'Check out Web Fundamentals — it rocks!',
      url: 'https://developers.google.com/web',
  })
    .then(() => console.log('Successful share'))
    .catch((error) => console.log('Error sharing', error));
}

Web Share API: Google's exclusive tool for sharing on social networks

Once this code is executed, a selection menu will open in Android and allow the website to share data with the user’s desired app. Of course, keep in mind that there are special conditions for using the Web Sahre API, which are:

– The site uses the HTTPS protocol
– This API can be called only in the response phase towards the user.
– The navigator.share() method cannot be called while the page is loading.
– Before using this API, you need to make sure that this functionality is available on the user side.

To begin with, you can share any type of link with the help of Web Share API, but for a pleasant user experience, it is recommended to use Canonical URL on your website. page to search engines.)

© 2022 Created with AloApi Team.