diff options
author | Teddy Wing | 2021-01-17 18:34:35 +0100 |
---|---|---|
committer | Teddy Wing | 2021-01-17 18:34:35 +0100 |
commit | bce9f260c66c7b4399d85eddc38c8d19dfa0cf43 (patch) | |
tree | 6f3bd9f869559df8f7314601040d338a96577932 /extension/background.js | |
parent | 19cf4f757250f92da5a4249c20781401c1750327 (diff) | |
download | extreload-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.
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 31 |
1 files changed, 31 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'); +} |