Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way through JavaScript to detect if a Safari Extension is already installed? https://extensions.apple.com has some way of doing it because they update the install link to "installed" if the extension is already installed. However, I can't figure out how they do it. I've traced it back to an object of type 'SafariExtensionGalleryController" but that's as far as I get.

Did Apple put special hooks into the extension system just for their stuff??

Lost...

Thx, Joel

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
864 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are the author of the extension, then you can detect if your own extension is installed. I simply inject an invisible string into my website which I then scan for when the page is loaded. If the string has been injected, my extension must be installed and you can then do whatever you like with the result.

identifier.js

if (window.top === window) 
{
    //detect if the extension has been installed and disable "Install" button if that's the case
    if (document.title === "YOUR PAGE TITLE") //we don't want to inject the string into any website, just ours
    {
        var p = document.createElement("noscript");
        var texto = document.createTextNode("Extension Installed");
        p.appendChild(texto);

        document.body.appendChild(p);
    }
}

I suspect Apple does this programmatically using the WebView that Safari uses to display websites and then runs javascript scripts internally that change the Extensions website depending on the extensions returned in Safari's code.

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...