| 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..269b0bdf0f4b35b53cf3b4ed4db9f9d04e10ecc2 100644
|
| --- a/go-back-with-backspace/background.js
|
| +++ b/go-back-with-backspace/background.js
|
| @@ -2,9 +2,42 @@
|
| // 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) {
|
| + 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) {
|
| + tabs.forEach(function(tab) {
|
| + scripts.forEach(function(script) {
|
| + // 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: script,
|
| + allFrames: true,
|
| + runAt: 'document_start'
|
| + });
|
| + });
|
| + });
|
| + });
|
| +}
|
|
|