add util to wait for tab loading

jh-changes
Shin'ya Ueoka 7 years ago
parent 8d3c79c63a
commit cf03d278eb
  1. 18
      e2e/ambassador/src/background/tabs.js

@ -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,
};