Index: go-back-with-backspace/background.js |
diff --git a/go-back-with-backspace/background.js b/go-back-with-backspace/background.js |
index 0c822a5e3343b6905ee986942eeb4db54e21c2d3..6a74d4b134923badf82f670f2596a6e243ee53ee 100644 |
--- a/go-back-with-backspace/background.js |
+++ b/go-back-with-backspace/background.js |
@@ -2,9 +2,43 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// Put up an informative message on first install. |
+// Inject the content scripts into all open tabs on first install or update. |
chrome.runtime.onInstalled.addListener(function(details) { |
- if (details.reason == "install") { |
- chrome.tabs.create({url: "pages/installed.html"}); |
- } |
+ if (details.reason == 'install' || details.reason === 'update') |
+ injectContentScripts(); |
}); |
+ |
+// Inject the content scripts into all open tabs when this extension is |
+// re-enabled. |
+chrome.management.onEnabled.addListener(function(info) { |
Devlin
2016/09/27 16:08:57
actually, the more I think about it, does this wor
Pam (message me for reviews)
2016/09/27 23:37:32
It works when I've tested it. Certainly there migh
|
+ if (info.id === chrome.runtime.id) |
+ injectContentScripts(); |
+}); |
+ |
+// Listen for messages from the content script, so an old version can detect |
+// the loss of connection and disable itself when the extension has been |
+// updated, disabled, or uninstalled. |
+chrome.runtime.onMessage.addListener(function(message, from, reply) { |
+ reply(); |
+}); |
+ |
+// Inject the content scripts into every open tab, on every window. |
+function injectContentScripts() { |
+ var scripts = chrome.runtime.getManifest().content_scripts[0].js; |
+ |
+ chrome.tabs.query({}, function(tabs) { |
+ for (var tab_index = 0; tab_index < tabs.length; ++tab_index) { |
Devlin
2016/09/27 16:08:57
suggestion:
for (let tab of tabs)
or
tabs.forEach(
Pam (message me for reviews)
2016/09/27 23:37:32
Done.
|
+ var tab = tabs[tab_index]; |
+ for (var i = 0; i < scripts.length; ++i) { |
+ // This will produce an error if extensions are prohibited on the |
+ // tab (e.g., chrome:// pages), but we can ignore it. |
+ chrome.tabs.executeScript(tab.id, |
+ { |
+ file: scripts[i], |
+ allFrames: true, |
+ runAt: 'document_start' |
+ }); |
+ } |
+ } |
+ }); |
+} |