aboutsummaryrefslogtreecommitdiff
path: root/e2e/ambassador/src/background/tabs.js
blob: d0495006feb0983cb3ba9c7136075ee3368bf79d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
    });
  });
};

const selectAt = (props = {}) => {
  return browser.tabs.query({ windowId: props.windowId }).then((tabs) => {
    let target = tabs[props.index];
    return browser.tabs.update(target.id, { active: true });
  });
};


export {
  create, selectAt
};