mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
8df8f81df7
* deprecate extensionizer for webextension-polyfill * fix tests * remove extensionizer * fix browser windows api calls * fix broken on firefox * fix getAcceptLanguages call * update more browser apis that are now promisified * remove unnecessary console error ignoring in e2e tests
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import browser from 'webextension-polyfill';
|
|
import log from 'loglevel';
|
|
|
|
const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
|
|
const tab = await new Promise((resolve) => {
|
|
browser.tabs.update(
|
|
onboardingInitiator.tabId,
|
|
{ active: true },
|
|
// eslint-disable-next-line no-shadow
|
|
(tab) => {
|
|
if (tab) {
|
|
resolve(tab);
|
|
} else {
|
|
// silence console message about unchecked error
|
|
if (browser.runtime.lastError) {
|
|
log.debug(browser.runtime.lastError);
|
|
}
|
|
resolve();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
export const returnToOnboardingInitiator = async (onboardingInitiator) => {
|
|
const tab = await new Promise((resolve) => {
|
|
// eslint-disable-next-line no-shadow
|
|
browser.tabs.get(onboardingInitiator.tabId, (tab) => {
|
|
if (tab) {
|
|
resolve(tab);
|
|
} else {
|
|
// silence console message about unchecked error
|
|
if (browser.runtime.lastError) {
|
|
log.debug(browser.runtime.lastError);
|
|
}
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
|
|
if (tab) {
|
|
await returnToOnboardingInitiatorTab(onboardingInitiator);
|
|
} else {
|
|
window.location.assign(onboardingInitiator.location);
|
|
}
|
|
};
|