检查Chrome扩展是否已安装。

3

我在Chrome Web Store上发布了一个Chrome扩展程序。

现在我想要从我的网站上实现内联安装。

我遵循了这个Chrome教程

所以我将我的网站添加为我的Chrome扩展的已验证站点,并且内联安装正常工作。

我遇到的问题是如何检查用户是否已经安装了我的扩展程序。

我想先检查用户是否安装了扩展程序,如果是,则不显示安装按钮,否则显示它。

在Chrome的内联安装教程中,有一个说明,说明如何通过检查chrome.app.isInstalled来检查扩展程序是否已安装。

但是即使扩展已安装,它总是返回false。我找不到使用此属性的详细说明。我想知道它是如何确定我正在检查哪个扩展程序的?它是根据<link>标签中的chrome信息吗?

<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/itemID">

任何帮助,如何正确检查用户是否已安装我的扩展?

1
chrome.app.isInstalled 是用于已安装的 Chrome 网络应用程序,而不是扩展(它们是不同的东西)。请参见常见问题解答中的此答案。您需要像 Mottie 建议的那样使用 Web 可访问资源。 - Petr Srníček
1个回答

2
我在YouTube上看到了一段安全视频,我不再有链接了,但我认为这是一个DefCon的演讲,或者什么...它展示了如何通过Chrome从浏览器URL访问扩展资源,如果该资源包含在manifest.json中的web_accessible_resources列表中。这可能不是一件好事...
因此,你可能会做到以下几点:
  • Create an image that says something like the extension is installed and active.
  • Add this image to your extension, and include it in the manifest.json under the web_accessible_resources list.
  • Then link to it on your webpage. The image will only be visible if the extension is installed and enabled.

    <img src="chrome-extension://{extension-id}/extension-enabled.png">
    
  • Use javascript to check and see if the image loaded. If it didn't, replace it with a url showing that the extension is disabled or not-installed.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接