ping/pong to fix openURL with message
in FF
This commit is contained in:
parent
85a9f6fb6a
commit
3c6a10f211
|
@ -66,11 +66,13 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
||||||
/* Same as openURL, the only extra prop in `opts` is `message` - it'll be sent when the tab is ready,
|
/* Same as openURL, the only extra prop in `opts` is `message` - it'll be sent when the tab is ready,
|
||||||
which is needed in the popup, otherwise another extension could force the tab to open in foreground
|
which is needed in the popup, otherwise another extension could force the tab to open in foreground
|
||||||
thus auto-closing the popup (in Chrome at least) and preventing the sendMessage code from running */
|
thus auto-closing the popup (in Chrome at least) and preventing the sendMessage code from running */
|
||||||
openURL(opts) {
|
async openURL(opts) {
|
||||||
const {message} = opts;
|
const tab = await openURL(opts);
|
||||||
return openURL(opts) // will pass the resolved value untouched when `message` is absent or falsy
|
if (opts.message) {
|
||||||
.then(message && (tab => tab.status === 'complete' ? tab : onTabReady(tab)))
|
await onTabReady(tab);
|
||||||
.then(message && (tab => msg.sendTab(tab.id, opts.message)));
|
await msg.sendTab(tab.id, opts.message);
|
||||||
|
}
|
||||||
|
return tab;
|
||||||
function onTabReady(tab) {
|
function onTabReady(tab) {
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
setTimeout(function ping(numTries = 10, delay = 100) {
|
setTimeout(function ping(numTries = 10, delay = 100) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user