0

I'd like a web page to offer a browser extension to Safari users. This web page already offers extensions to Google Chrome and Firefox users.

In Chrome, the Javascript expression typeof chrome.webstore.install !== 'undefined' comes back true if it's possible to offer the user the Chrome extension.

In Firefox, it's typeof InstallTrigger !== 'undefined'.

Is there a similar expression that will return true if it's possible to install a Safari extension?

O. Jones
  • 103,626
  • 17
  • 118
  • 172

1 Answers1

1

Apple is strongly encouraging extension developers to submit their extensions to the Safari Extensions Gallery.

If you distribute your extension from your own site, the install process for users is suboptimal, and there are multiple "Trust" dialogs that users have to consent to.

As far as I'm aware, all that can be done from your own website for Safari is:

1. Detect that the browser is Safari.

Although browser detection is not 100% effective, and feature-based detection is preferred, in this case you can follow up your effective feature-based detection of Chrome and Firefox with a simple, fairly effective test for Safari (the key being the check on navigator.vendor):

var isSafari = /Apple Computer/.test(navigator.vendor) && /Safari/.test(navigator.userAgent);

Alternatively, you can use one of the more complex browser detection scripts that handles minor browsers as well.

2. Optionally detect the version of Safari

If you need functionality available in a specific release of Safari, you can optionally follow this with a browser version check.

function getSafariVersion() {
    var index = navigator.userAgent.indexOf("Version");
    if (index == -1) return;
    return parseFloat(navigator.userAgent.substring(index+"Version".length+1));
}

Note: If the user has altered their browser's User-Agent, this check will not be accurate.

3. Offer the .safariextz for download, and ask the user to open it.

Link to the extension bundle, encourage the user to download it, and provide instructions (and ideally screenshots) of the manual install process.

(This is what 1Password does on their extension install page.)


Bonus:

To handle the case where users already have your extension installed, there are various methods to detect whether your Safari extension is installed from your website.

Community
  • 1
  • 1
breakingobstacles
  • 2,815
  • 27
  • 24
  • The relevant part of your answer is "detect that the browser is Safari/detect version". And that's the exact part you don't explain how to do in practice (and the question was about that). Please expand on that. – Xan Sep 30 '16 at 08:45
  • Examples (and links to alternative methods) added. – breakingobstacles Sep 30 '16 at 13:45