[epiphany/pgriffis/web-extension/runtime-send-message: 8/11] WebExtensions: Implement compat with chrome.extension.lastError
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/runtime-send-message: 8/11] WebExtensions: Implement compat with chrome.extension.lastError
- Date: Thu, 2 Jun 2022 18:44:28 +0000 (UTC)
commit 5ec1251300e8bff2f272c847da69c81f878529d6
Author: Patrick Griffis <pgriffis igalia com>
Date: Thu Jun 2 10:25:59 2022 -0500
WebExtensions: Implement compat with chrome.extension.lastError
.../resources/js/webextensions-common.js | 15 +++++++++++++--
embed/web-process-extension/resources/js/webextensions.js | 1 +
2 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/embed/web-process-extension/resources/js/webextensions-common.js
b/embed/web-process-extension/resources/js/webextensions-common.js
index a3b03457a..411411bad 100644
--- a/embed/web-process-extension/resources/js/webextensions-common.js
+++ b/embed/web-process-extension/resources/js/webextensions-common.js
@@ -36,7 +36,7 @@ class EphyEventListener {
for (const listener of this._listeners) {
const ret = listener.callback (message, sender, reply_callback);
if (typeof ret === 'object' && typeof ret.then === 'function') {
- ret.then(x => { reply_callback(x); }).catch(x => { reply_callback(); })
+ ret.then(x => { reply_callback(x); }).catch(x => { reply_callback(); });
handled = true;
} else if (ret === true) {
// We expect listener.callback to call `reply_callback`.
@@ -57,11 +57,21 @@ const ephy_message = function (fn, args) {
return new Promise (function (resolve, reject) {
const resolve_wrapper = function (x) {
+ window.browser.extension.lastError = null;
if (callback !== undefined)
callback (x);
resolve (x);
};
- ephy_send_message (fn, args, resolve_wrapper, reject);
+ const reject_wrapper = function (x) {
+ if (callback !== undefined) {
+ window.browser.extension.lastError = new Error(x);
+ callback ();
+ return;
+ }
+ reject(x);
+ };
+
+ ephy_send_message (fn, args, resolve_wrapper, reject_wrapper);
});
};
@@ -73,6 +83,7 @@ window.browser.runtime = {
sendMessage: function (...args) {
return ephy_message ('runtime.sendMessage', args);
},
+ lastError: null,
};
diff --git a/embed/web-process-extension/resources/js/webextensions.js
b/embed/web-process-extension/resources/js/webextensions.js
index 0577555ad..c82b807f2 100644
--- a/embed/web-process-extension/resources/js/webextensions.js
+++ b/embed/web-process-extension/resources/js/webextensions.js
@@ -65,6 +65,7 @@ window.browser.runtime.onInstalled = new EphyEventListener ();
window.browser.runtime.onMessageExternal = new EphyEventListener ();
window.browser.runtime.sendNativeMessage = function (...args) { return ephy_message
('runtime.sendNativeMessage', args); };
window.browser.runtime.getBackgroundPage = window.browser.extension.getBackgroundPage;
+Object.defineProperty(window.browser.runtime, 'lastError', { get: function() { return
window.browser.extension.lastError; } });
window.browser.pageAction = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]