如何检查Chrome扩展程序是否已完全安装

Woo*_*ome 8 javascript google-chrome google-chrome-extension

使用Chrome网上应用店内联安装(https://developers.google.com/chrome/web-store/docs/inline_installation),可以指定在chrome.webstore.install()成功安装扩展程序时执行的回调.

通过一些非常繁琐的调试,我了解到在执行回调时不必100%安装扩展 - 可能是后台尚未加载或内容脚本尚未可用.

在我的特定情况下,问题以这种方式出现:

  1. 用户单击chrome.webstore.install()绑定到onclick事件的安装按钮.
  2. 成功回调注入iFrame.
  3. 内容脚本是为iFrame定义的,并注入了一些完成工作
  4. 内容脚本返回完整的安装对话框.

第3步是问题所在.有时在内容脚本完全加载之前会注入iFrame,因此不会注入任何脚本(内容脚本仅注入新创建的iFrame内,而不是在安装/启用扩展时已存在的iFrame).

我知道有可能的解决方法,例如扩展本身注入iFrame或简单setTimeout(),但为了帮助其他人,我认为值得提问:

如果chrome.webstore.install()回调无法确保,我怎么能确定扩展是100%安装的呢?

使用检查用户是否安装了某个扩展程序<img>描述的着名加载方法无法可靠地工作(对于那些认为是解决方案的人).

Meh*_*sly 8

这是这样做的方法:

http://code.google.com/chrome/extensions/extension.html#global-events

如下面的最后一个链接所述,您应该能够:

var myPort=chrome.extension.connect('yourextensionid_qwerqweroijwefoijwef', some_object_to_send_on_connect);
Run Code Online (Sandbox Code Playgroud)

您还可以在下一个链接中检查检查项目是否已安装部分:

https://developers.google.com/chrome/web-store/docs/inline_installation

或者你可以按照这篇文章中的内容进行操作:

检查用户是否安装了Chrome扩展程序

我还看到了解决背景页面和本地存储的解决方案:

http://developer.chrome.com/extensions/background_pages.html

Chrome扩展程序安装后挂钩/ API功能:它是否存在?