Almost all websites feature a row of brightly colored sharing-buttons at the top or bottom of each page. These buttons keep the big social networks at the front of people’s minds while also enabling the same networks to spy on people across the web.
The buttons even pose a legal risk to website owners. More than 400 000 websites still proudly feature sharing buttons for long-gone social-sharing networks of the past like Digg, StumbleUpon, and Google+.
Surely there must be a better way! The new Web Share API draft gives websites access to the native sharing tools built-in to modern operating systems. The draft API is only supported by Google Chrome version 61+ on Android, and Safari 12+ on iOS and MacOS. However, it holds a promise of being a more privacy-preserving and unified user experience for content sharing.
Rather than being a promotional/spying-tool, the operating system’s native sharing tool is extendable and personalized. It enables quick sharing to the apps and services the user has installed and actually uses, without leaking personal data about their browsing habits to other parties.
It’s not limited to just social networks. The native share dialogs support other types of apps like reading-lists, note-taking, email, and more.
It’s really easy to implement the Web Share API. I’ll get back to a complete implementation example later in the article. However, one big unanswered question remains: what do you do with unsupported web browsers?
A common fallback is to hard-code fallback links to share the content on either Facebook or Twitter. I don’t want to push my readers to any of these services. Especially not after they’ve clicked on a somewhat ambiguous “Share” button.
A rather obvious choice is to outsource to one of the many multi-network content sharing services. However, the leading providers like AddThis and ShareThis are slow to load, collect a large amount of personal data about readers, and require a lot of work to integrate.
AddToAny has sharing widgets similar to the ones offered by AddThis and directly by the different social networks. However, it also has an easy-to-integrate API endpoint with a good selection of sharing services. The service is built with privacy-by-default.
Let’s get back to the Web Share API. You can easily feature-test for support by testing for
navigator.share. If present, you provide it an object with the
url you want to share.
When the feature-test fails, you can fallback to opening a window with AddToAny. The page to open must follow this URL pattern:
You can supply the two parameters with hardcoded values, or URL-encoded values from
You can get higher-quality data sources of existing metadata elements, if your websites deploy them. You can use the canonical link and the meta title as shown below:
You may have noticed that AddToAny’s use of a fragment to parse variables means that these aren’t sent to AddToAny’s servers. (Except by misbehaving HTTP clients.) These values are read client-side on the sharing page; minimizing the data that is shared with AddToAny
The following example shows a complete implementation of the Web Share API and includes a fallback that opens a new window to sharing with AddToAny:
You’d call this in response to a click event on your share button design. The complications around
window.open are there to properly mitigate tabnabbing.
People can manually customize the list of services shown in AddToAny. The service doesn’t make any personalizations on its own. The default list places Facebook and Twitter on top, which should cover the most popular services. It also contains a wide variety of services including Instapaper, Blogger, Mastodon, and 85 others.
AddToAny doesn’t optimize which services are places on the top of the list by regions. For example, it doesn’t know to move Sina Weibo and RenRen to the top of the list in China, or VKontakte to the top in Russia. This would be a nice feature to have.