How to use the webextension-polyfill.tabs function in webextension-polyfill

To help you get started, we’ve selected a few webextension-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lusakasa / saka / src / background_page / index.js View on Github external
async function toggleSaka(tabId) {
  if (SAKA_DEBUG) console.group('toggleSaka');
  // Get the specified tab, or the current tab if none is specified
  const currentTab =
    tabId === undefined
      ? (await browser.tabs.query({
          active: true,
          currentWindow: true
        }))[0]
      : await browser.tabs.get(tabId);
  if (currentTab) {
    // If the current tab is Saka, switch to the previous tab (if it exists) and close the current tab
    if (currentTab.url === browser.runtime.getURL('saka.html')) {
      if (lastTabId) {
        try {
          const lastTab = await browser.tabs.get(lastTabId);
          if (lastTab) {
            try {
              await browser.tabs.update(lastTabId, { active: true });
              if (SAKA_DEBUG) console.log(`Switched to tab ${lastTab.url}`);
            } catch (e) {
              if (SAKA_DEBUG)
github cnwangjie / better-onetab / src / common / tabs.js View on Github external
const openTabLists = async () => {
  // open only one in a window
  const window = await browser.runtime.getBackgroundPage()
  if (!_.isObject(window.appTabId)) window.appTabId = {}
  const currentWindow = await browser.windows.getCurrent()
  const windowId = currentWindow.id
  const tabListsUrl = browser.runtime.getURL('index.html#/app/')
  if (windowId in window.appTabId) {
    const tabs = await getAllInWindow(windowId)
    const tab = tabs.find(tab => tab.id === window.appTabId[windowId])
    if (tab) {
      if (tab.url.startsWith(tabListsUrl)) {
        return browser.tabs.update(tab.id, { active: true })
      }
      delete window.appTabId[windowId]
    }
  }
  const createdTab = await browser.tabs.create({url: tabListsUrl})
  window.appTabId[windowId] = createdTab.id
}
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-client / index.js View on Github external
async function _reloadIpfsClientDependents (instance, opts) {
  // online || offline
  if (browser.tabs && browser.tabs.query) {
    const tabs = await browser.tabs.query({})
    if (tabs) {
      tabs.forEach((tab) => {
        // detect bundled webui in any of open tabs
        if (_isWebuiTab(tab.url)) {
          browser.tabs.reload(tab.id)
          log('reloading bundled webui')
        }
      })
    }
  }
  // online only
  if (client && instance) {
    // add important data to local ipfs repo for instant load
    precache(instance)
  }
}
github AztecProtocol / AZTEC / packages / extension / src / utils / hot-reload.js View on Github external
const reload = async () => {
    const tabs = await browser.tabs.query({ active: true, currentWindow: true });

    if (tabs[0]) {
        console.log('tabs', tabs);
        browser.tabs.reload(tabs[0].id);
    }

    browser.runtime.reload();
};
github toggl / toggl-button / src / scripts / components / LoginPage.tsx View on Github external
const openPage = (url: string) => () => browser.tabs.create({ url });
github sienori / Tab-Session-Manager / src / background / background.js View on Github external
const addListeners = () => {
  const handleReplace = () => replacePage();
  browser.tabs.onActivated.addListener(handleReplace);
  browser.windows.onFocusChanged.addListener(handleReplace);

  browser.storage.onChanged.addListener((changes, areaName) => {
    handleSettingsChange(changes, areaName);
    setAutoSave(changes, areaName);
    updateLogLevel();
  });

  browser.tabs.onUpdated.addListener(handleTabUpdated);
  browser.tabs.onRemoved.addListener(handleTabRemoved);
  browser.tabs.onCreated.addListener(setUpdateTempTimer);
  browser.tabs.onMoved.addListener(setUpdateTempTimer);
  browser.windows.onCreated.addListener(setUpdateTempTimer);

  browser.windows.onRemoved.addListener(autoSaveWhenWindowClose);
};
github SeleniumHQ / selenium-ide / packages / selenium-ide-extension / src / neo / IO / SideeX / find-select.js View on Github external
function endSelection(tabId) {
  UiState.setSelectingTarget(false)
  browser.tabs
    .sendMessage(tabId, { selectMode: true, selecting: false })
    .catch(() => {})
}
github dessant / clear-browsing-data / src / background / main.js View on Github external
if (tab.id !== tempTabId) {
          reloadingTabs.push(browser.tabs.reload(tab.id, {bypassCache: true}));
        }
      }

      await Promise.all(reloadingTabs);
    } else if (options.reloadTabs === 'active') {
      if (['allButActive', 'false'].includes(options.closeTabs)) {
        await browser.tabs.reload(activeTabId, {bypassCache: true});
      }
    } else if (options.reloadTabs === 'allButActive') {
      const reloadingTabs = [];
      const tabs = await browser.tabs.query({});
      for (const tab of tabs) {
        if (![activeTabId, tempTabId].includes(tab.id)) {
          reloadingTabs.push(browser.tabs.reload(tab.id, {bypassCache: true}));
        }
      }

      await Promise.all(reloadingTabs);
    }
  }
}
github sienori / simple-translate / src / popup / components / PopupPage.js View on Github external
const getTabInfo = async () => {
  try {
    const tab = (await browser.tabs.query({ currentWindow: true, active: true }))[0];
    const tabUrl = browser.tabs.sendMessage(tab.id, { message: "getTabUrl" });
    const selectedText = browser.tabs.sendMessage(tab.id, { message: "getSelectedText" });
    const isEnabledOnPage = browser.tabs.sendMessage(tab.id, { message: "getEnabled" });

    const tabInfo = await Promise.all([tabUrl, selectedText, isEnabledOnPage]);
    return {
      isConnected: true,
      url: tabInfo[0],
      selectedText: tabInfo[1],
      isEnabledOnPage: tabInfo[2]
    };
  } catch (e) {
    return { isConnected: false, url: "", selectedText: "", isEnabledOnPage: false };
  }
};
github cliffordfajardo / cato / app / plugins / close-tabs-except-active / index.js View on Github external
async function closeTabsExceptCurrent() {
  const otherTabs = await browser.tabs.query({'active': false, currentWindow: true})
  for(const tab of otherTabs) {
    await browser.tabs.remove(tab.id)
  }
  const popupWindow = await browser.extension.getViews({type: 'popup'})[0]
  popupWindow.close()
}