aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-01-17 18:34:35 +0100
committerTeddy Wing2021-01-17 18:34:35 +0100
commitbce9f260c66c7b4399d85eddc38c8d19dfa0cf43 (patch)
tree6f3bd9f869559df8f7314601040d338a96577932
parent19cf4f757250f92da5a4249c20781401c1750327 (diff)
downloadextreload-bce9f260c66c7b4399d85eddc38c8d19dfa0cf43.tar.bz2
Set up Native Messaging and reload extensions
Get the extension IDs from the Native Messaging host and reload the specified extensions. Also reload the current tab. Turns out this doesn't work the way I expected. It does disable and re-enable the extension, but it doesn't reload the extension as with `chrome.runtime.reload()`. This means the specified extension isn't reloaded with the latest code changes. Unfortunately, it looks like there's no API to do what I want, and unless there's some magic in the `chrome.debugger` API I'll have to give up on this project.
-rw-r--r--extension/background.js31
-rw-r--r--extension/manifest.json1
2 files changed, 32 insertions, 0 deletions
diff --git a/extension/background.js b/extension/background.js
new file mode 100644
index 0000000..fa7defb
--- /dev/null
+++ b/extension/background.js
@@ -0,0 +1,31 @@
+var NATIVE_HOST_ID = 'com.teddywing.extreload';
+var port = null;
+
+port = chrome.runtime.connectNative(NATIVE_HOST_ID);
+port.onMessage.addListener(on_native_message);
+port.onDisconnect.addListener(on_disconnected);
+
+function on_native_message(message) {
+ console.log(message);
+
+ if (message.ids) {
+ message.ids.forEach(function(id) {
+ // Disable extension
+ chrome.management.setEnabled(id, false, function() {
+ console.log('Disabled', id);
+
+ // Enable extension
+ chrome.management.setEnabled(id, true, function() {
+ console.log('Enabled', id);
+
+ // Reload the current tab
+ chrome.tabs.reload();
+ });
+ });
+ });
+ }
+}
+
+function on_disconnected() {
+ console.warn('Native host disconnected');
+}
diff --git a/extension/manifest.json b/extension/manifest.json
index 2b6ad1c..8db1261 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -11,6 +11,7 @@
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr45Ldq/GXNl/vHcN2dN0cbABlF/T/Lx0ebJzV3ubxngxpciEt6VNVAoeBWdncYxIpAUKY2sSq/evBvzgclz+Hg4yc+/+UvVDwMJXvTmw7Y3bB8eFLtUmO+ekuQuRFRHKQGN3UJF8d+wJnVd7aOzAiyswtg3SOEihCY+WBooIjSyck2uJ0XgY6lHNNwDntn2iHg3mro3XSfoCjaC3k63IzORYp10zUhZiQJI+uOUK+pYzvCnXTMg/bhZYz6RIdaPkv7u0PNefxOH1cUHcu9PBx22IiD/FKVj8zMt6erLm7UzUUGdkltST8AF/btBzzdzxVAokjQa80Of94dQN82KnwQIDAQAB",
"permissions": [
+ "nativeMessaging",
"management"
]
}