检测是否安装了Safari扩展
有没有办法通过JavaScript来检测是否已安装Safari扩展程序? https://extensions.apple.com 有一些方法可以实现,因为他们将安装链接更新为已安装如果已安装扩展名。但是,我无法弄清楚他们是如何做到的。我已经将它追溯到'SafariExtensionGalleryController'类型的对象,但这就是我得到的。
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.
Apple是否为扩展系统添加了特殊的钩子??
Did Apple put special hooks into the extension system just for their stuff??
失去...
Thx,Joel
如果您是扩展程序的作者,那么您可以检测是否安装了自己的扩展程序。我只是将一个不可见的字符串注入我的网站,然后我在页面已加载。如果已注入字符串,则必须安装我的扩展程序,然后您可以随意执行任何结果。
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);
}
}
我怀疑Apple使用Safari的WebView以编程方式执行此操作用于显示网站,然后在内部运行javascript脚本,根据Safari代码中返回的扩展名更改Extensions网站。
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.
希望这会有所帮助!