From c6d346cc79d8141cfc2e48ee8b97f79cc2f20188 Mon Sep 17 00:00:00 2001 From: Dave Hughes Date: Tue, 29 Sep 2020 09:50:24 -0700 Subject: [PATCH 1/2] Handle edge case with no callbackArgs This is an alternative approach to fixing #23. For chrome functions that pass no arguments to their callbacks, we should try to propagate the function's own return value. Honestly, I'm pretty confused about how it is even able to work. It makes sense, kind of, but I'm surprised that I can access the function return inside an arrow function defined as an inline function argument. In any case, I tested and confirmed that this works. Fixes #23 and closes #26. --- chrome-extension-async.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome-extension-async.js b/chrome-extension-async.js index 4e3578e..838e8fb 100644 --- a/chrome-extension-async.js +++ b/chrome-extension-async.js @@ -31,7 +31,7 @@ return new Promise((resolve, reject) => { try { // Try to run the original function, with the trimmed args list - f(...safeArgs, (...cbArgs) => { + const ret = f(...safeArgs, (...cbArgs) => { // If a callback was passed at the end of the original arguments if (callback) { @@ -50,7 +50,7 @@ resolve(cbObj); } else if (!cbArgs || cbArgs.length === 0) - resolve(); + resolve(ret); // if there were no callback args, resolve with the function's own return value else if (cbArgs.length === 1) resolve(cbArgs[0]); else From 5a705c4c907a7cd53e213744c0aded864a6712a5 Mon Sep 17 00:00:00 2001 From: Dave Hughes Date: Tue, 29 Sep 2020 09:50:26 -0700 Subject: [PATCH 2/2] Revert "Remove non-standard `contextMenus.create`" This reverts commit ab19d0db172e5b1df7fcb2820e0dcd4a5d58c3c4. That was introduced in PR #26 as an alternative approach to #27. However with the more consistent solution of #27, `contextMenus.create` should be promisified, in order to ensure a consistent API (so it returns a Promise, like everything else). --- chrome-extension-async.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome-extension-async.js b/chrome-extension-async.js index 838e8fb..5e7caae 100644 --- a/chrome-extension-async.js +++ b/chrome-extension-async.js @@ -155,7 +155,7 @@ { n: 'camera', props: knownInContentSetting }, { n: 'unsandboxedPlugins', props: knownInContentSetting }, { n: 'automaticDownloads', props: knownInContentSetting }], - contextMenus: ['update', 'remove', 'removeAll'], /* 'create' omitted intentionally, it does not follow standard asynchronous pattern */ + contextMenus: ['create', 'update', 'remove', 'removeAll'], cookies: ['get', 'getAll', 'set', 'remove', 'getAllCookieStores'], debugger: ['attach', 'detach', 'sendCommand', 'getTargets'], desktopCapture: ['chooseDesktopMedia'],