最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to check if Chrome extension has fully installed - Stack Overflow

programmeradmin2浏览0评论

Using Chrome Web Store inline installation ( ) it is possible to specify a callback for chrome.webstore.install() that will be executed when the extension is successfully installed.

Through some very tedious debugging I've learned that extensions are not neccessarily 100% installed when the callback is executed - maybe the background hasn't been loaded or content scripts aren't yet available.

In my particular case the problem presents itself in this way:

  1. User clicks install button with chrome.webstore.install() bound to onclick event.
  2. Success callback injects an iFrame.
  3. Content script is defined for the iFrame and injected to do some finishing work
  4. Content script returns with a pleted installation dialog.

Step 3 is the problem. Some times the iFrame will be injected before content script is fully loaded and thus no script will be injected (content scripts are only injected inside newly created iFrames, not iFrames already existing when the extension is installed/enabled).

I know there are possible workarounds such as having the extension itself inject the iFrame or a simple setTimeout(), but for the sake of helping others I think it's worth asking the question:

How can I be certain that the extension is 100% installed, when the chrome.webstore.install() callback doesn't ensure it?

Using the famous <img> load method described in Checking if user has a certain extension installed doesn't work reliably (for those thinking that'd be a solution).

Using Chrome Web Store inline installation ( https://developers.google./chrome/web-store/docs/inline_installation ) it is possible to specify a callback for chrome.webstore.install() that will be executed when the extension is successfully installed.

Through some very tedious debugging I've learned that extensions are not neccessarily 100% installed when the callback is executed - maybe the background hasn't been loaded or content scripts aren't yet available.

In my particular case the problem presents itself in this way:

  1. User clicks install button with chrome.webstore.install() bound to onclick event.
  2. Success callback injects an iFrame.
  3. Content script is defined for the iFrame and injected to do some finishing work
  4. Content script returns with a pleted installation dialog.

Step 3 is the problem. Some times the iFrame will be injected before content script is fully loaded and thus no script will be injected (content scripts are only injected inside newly created iFrames, not iFrames already existing when the extension is installed/enabled).

I know there are possible workarounds such as having the extension itself inject the iFrame or a simple setTimeout(), but for the sake of helping others I think it's worth asking the question:

How can I be certain that the extension is 100% installed, when the chrome.webstore.install() callback doesn't ensure it?

Using the famous <img> load method described in Checking if user has a certain extension installed doesn't work reliably (for those thinking that'd be a solution).

Share Improve this question edited May 23, 2017 at 12:14 CommunityBot 11 silver badge asked Aug 21, 2012 at 8:55 WoodgnomeWoodgnome 2,4015 gold badges29 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8 +100

This is the way to do it :

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

As mentioned in the last link below , you should be able to do :

var myPort=chrome.extension.connect('yourextensionid_qwerqweroijwefoijwef', some_object_to_send_on_connect);

You can also check Checking if an item is already installed section in the next link :

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

or you can follow what have been done in this post:

Check whether user has a Chrome extension installed

I also saw solutions talking about background page and localstorage:

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

Chrome extension post-install hook/API function: does it exist?

发布评论

评论列表(0)

  1. 暂无评论