18

I have been trying to trigger the Intent Share in the Android browser from javascript using the navigator.share.

Following is an example code:

$("#printTest").click(function(e){
    if (navigator.share === undefined){
        alert('Undefined!');
    }
    else{
        alert('Sharing!');
        navigator.share({title: 'Example Page', text: 'https://example.com'});
    }
});

When I try to click on the button from chrome in ubuntu, it opens a window for sharing(which shows no apps to select though). But the same is not working on any android mobile browser. I have tested in Chrome for Android version 64 and Chrome for Android Dev also. All of the shows the alert 'Undefined' even after enabling the flag chrome://flags/#enable-experimental-web-platform-features.

Gopakumar N G
  • 1,775
  • 1
  • 23
  • 40

1 Answers1

98

navigator.share will only work on websites with https and not HTTP

Gopakumar N G
  • 1,775
  • 1
  • 23
  • 40
  • 1
    damn and lets encrypt only give certificate for dns names and no ip... basically you have to pay a domain to test this function. – Nicolas Manzini Apr 28 '19 at 15:41
  • 2
    Sharing will work if you are on http://localhost. If you developing on mobile, you can use port forwarding to use localhost domain on phone even if your local server is on PC. – Dread Boy Mar 17 '20 at 15:00
  • @NicolasManzini for local testing over HTTPS you could use [ngrok](https://ngrok.com/) – skyllet Jan 10 '21 at 20:51
  • 1
    @NicolasManzini I would never recommend ngrok to a casual developer or for use in a company without checking with cyber security guys first. It is a MASSIVE security risk to do this and is a well known entry point for malicious hackers. – AhrenFullStop Jun 21 '21 at 22:48