diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-02-14 18:49:55 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-02-14 18:49:55 +0100 |
commit | cf838016b70bc55d8fb19a10b4deb580289e3769 (patch) | |
tree | 8c6e8f271e38f8cf7edd7ae733b68ac70c2b7076 /common | |
parent | 1869062a9d6ae736bdfe5e2993dfe1f280af4d8b (diff) | |
download | browser-extension-cf838016b70bc55d8fb19a10b4deb580289e3769.tar.gz browser-extension-cf838016b70bc55d8fb19a10b4deb580289e3769.zip |
restore chromium support
Diffstat (limited to 'common')
-rw-r--r-- | common/broadcast.js | 2 | ||||
-rw-r--r-- | common/browser.js | 22 |
2 files changed, 22 insertions, 2 deletions
diff --git a/common/broadcast.js b/common/broadcast.js index 12b365a..3cc09b5 100644 --- a/common/broadcast.js +++ b/common/broadcast.js @@ -119,6 +119,6 @@ function close(conn) { if (conn.type === "sender") flush(conn); - setTimeout(conn.port.disconnect()); + setTimeout(() => conn.port.disconnect()); } #EXPORT close diff --git a/common/browser.js b/common/browser.js index 4830774..582d2a4 100644 --- a/common/browser.js +++ b/common/browser.js @@ -3,7 +3,7 @@ * * Function: Export the browser API object. * - * Copyright (C) 2021 Wojtek Kosior + * Copyright (C) 2021, 2022 Wojtek Kosior * * This program is free software: you can redistribute it and/or modify * it under the terms of the CC0 1.0 Universal License as published by @@ -21,6 +21,26 @@ #ELIF CHROMIUM +/* Use promises for sendMessage(). */ +function response_cb(resolve, reject, response) { + if (arguments.length < 3) + reject(chrome.runtime.lastError); + else + resolve(response); +} + +function replacement_sendMessage(old_sendMessage, ...args) { + let callbacks, prom = new Promise((...cbs) => callbacks = cbs); + old_sendMessage(...args, resp => response_cb(...callbacks, resp)); + return prom; +} + +for (const api_object of [chrome.tabs, chrome.runtime].filter(a => a)) { + const old_sendMessage = api_object.sendMessage; + api_object.sendMessage = + (...args) => replacement_sendMessage(old_sendMessage, ...args); +} + #EXPORT chrome AS browser #ENDIF |