add util to wait for tab loading
This commit is contained in:
parent
8d3c79c63a
commit
cf03d278eb
1 changed files with 18 additions and 0 deletions
18
e2e/ambassador/src/background/tabs.js
Normal file
18
e2e/ambassador/src/background/tabs.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
const create = (props = {}) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
browser.tabs.create(props).then((createdTab) => {
|
||||||
|
let callback = (tabId, changeInfo, tab) => {
|
||||||
|
if (tab.url !== 'about:blank' && tabId === createdTab.id &&
|
||||||
|
changeInfo.status === 'complete') {
|
||||||
|
browser.tabs.onUpdated.removeListener(callback);
|
||||||
|
resolve(tab);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
browser.tabs.onUpdated.addListener(callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
create,
|
||||||
|
};
|
Reference in a new issue