1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 04:37:13 +01:00
metamask-extension/ui/pages/first-time-flow/onboarding-initiator-util.js
Alex Donesky 12a088e638
Fix browser.tab.get call (#14550)
* update to expect promise from browser api polyfill rather than pass callback
2022-04-29 09:21:06 -05:00

27 lines
723 B
JavaScript

import browser from 'webextension-polyfill';
import log from 'loglevel';
export const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
let tab;
try {
tab = await browser.tabs.update(onboardingInitiator.id, {
active: true,
});
} catch (error) {
log.debug(
`An error occurred while updating tabs in returnToOnboardingInitiatorTab: ${error.message}`,
);
}
if (tab) {
window.close();
} else {
// this case can happen if the tab was closed since being checked with `browser.tabs.get`
log.warn(
`Setting current tab to onboarding initiator has failed; falling back to redirect`,
);
window.location.assign(onboardingInitiator.location);
}
};