I had the exact same problem with my Reload All Tabs extension. Basically, when the extension first gets installed, the user can't use it unless they reload the tabs. As you know, it is really bad user experience automatically reloading users tabs because they might be in a middle of doing something and they will loose it. I ended up using executeScript
because it is really invisible to the user. You can see the source code located at GitHub:
https://github.com/mohamedmansour/reload-all-tabs-extension/blob/master/js/reload_controller.js#L96
Basically I used the approach to target installations from this question, Detect Chrome extension first run / update and used the chrome.windows.getAll
, chrome.tabs.getAllInWindow
, and chrome.tabs.executeScript
to prepare the extension when it has first installed.
chrome.windows.getAll({ populate: true }, function(windows) {
for (var w = 0; w < windows.length; w++) {
var tabs = windows[w].tabs;
for (var t = 0; t < tabs.length; t++) {
var tab = tabs[t];
// Only inject in web pages.
if (tab.url.indexOf('http') == 0) {
chrome.tabs.executeScript(tab.id, { file: 'content_script.js', allFrames: true });
}
}
}
});
If executeScript doesn't work, please file a bug at http://crbug.com/new and the developers can look at it. In my case, it works just fine.
Hope that helps!