How to use the webextension-polyfill.windows 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
console.warn(
            `Failed to execute Saka into tab. Instead, created new Saka tab after ${
              currentTab.url
            }`
          );
      }
    }
    // If tab couldn't be found (e.g. because query was made from devtools) create a new tab
  } else {
    await browser.tabs.create({
      url: '/saka.html'
    });
    if (SAKA_DEBUG)
      console.log("Couldn't find tab. Instead, created new Saka tab.");
  }
  const window = await browser.windows.getLastFocused();
  await browser.windows.update(window.id, { focused: true });
  if (SAKA_DEBUG) console.groupEnd();
}
github SeleniumHQ / selenium-ide / packages / selenium-ide-extension / src / background / background.js View on Github external
window.openedWindowIds.map(windowId =>
        browser.windows.remove(windowId).catch(() => {
          /* Window was removed previously by the user */
        })
      )
github lusakasa / saka / src / suggestion_engine / server / index.js View on Github external
async function focusOrCreateTab(url) {
  const matchingTabs = await browser.tabs.query({ url });

  if (matchingTabs && matchingTabs.length > 0) {
    // If multiple matching tabs then just focus the first one
    const existingTab = matchingTabs[0];

    await browser.tabs.update(existingTab.id, { active: true });
    await browser.windows.update(existingTab.windowId, { focused: true });
  } else {
    await browser.tabs.create({ url });
  }
}
github SeleniumHQ / selenium-ide / packages / side-recorder / src / background / window-session.js View on Github external
async closeAllOpenedWindows() {
    const windowIds = Object.keys(this.openedWindowIds).map(id => parseInt(id))
    for (let windowId of windowIds) {
      await browser.windows.remove(windowId)
    }
    this.openedWindowIds = {}
  }
github SeleniumHQ / selenium-ide / packages / selenium-ide-extension / src / background / background.js View on Github external
function openPanel(tab) {
  let contentWindowId = tab.windowId
  if (ideWindowId) {
    browser.windows
      .update(ideWindowId, {
        focused: true,
      })
      .catch(function() {
        ideWindowId == undefined
        openPanel(tab)
      })
    return
  } else if (!clickEnabled) {
    return
  }

  clickEnabled = false
  setTimeout(function() {
    clickEnabled = true
  }, 1500)
github sienori / Tab-Session-Manager / src / popup / actions / controlSessions.js View on Github external
export const addCurrentWindow = async id => {
  log.info(logDir, "AddCurrentWindow()", id);
  const session = await getSessions(id);
  const currentWindow = await browser.windows.getCurrent({ populate: true });

  //tabIdをユニークなIDに更新してマップに格納
  let tabIdList = Object.values(session.windows).flatMap(window =>
    Object.values(window).map(tab => tab.id)
  );
  let updatedTabIdMap = {};
  for (const tab of currentWindow.tabs) {
    const isTabIdDuplicate = id => tabIdList.some(tabId => tabId == id);
    const newTabId = generateUniqueId(tab.id, isTabIdDuplicate);
    updatedTabIdMap[tab.id] = newTabId;
    tabIdList.push(newTabId);
  }

  const isWindowIdDuplicate = id => session.windows.hasOwnProperty(id);
  const windowId = generateUniqueId(currentWindow.id, isWindowIdDuplicate);
github xcv58 / Tab-Manager-v2 / src / js / libs / index.tsx View on Github external
export const openPopup = () => {
  const { availHeight, availLeft, availTop, availWidth } = screen
  const width = getInt(Math.max(MAX_WIDTH, availWidth / 2))
  const height = getInt(Math.max(MAX_HEIGHT, availHeight / 2))
  const top = getInt(availTop + (availHeight - height) / 2)
  const left = getInt(availLeft + (availWidth - width) / 2)
  browser.windows.create({
    top,
    left,
    height,
    width,
    url: popupURL,
    type: 'popup'
  })
}
github cnwangjie / better-onetab / src / background.js View on Github external
const dynamicDisableMenu = async () => {
  const groupedTabs = await tabs.groupTabsInCurrentWindow()
  const windows = await browser.windows.getAll()
  browser.contextMenus.update('STORE.STORE_LEFT_TABS', {
    enabled: groupedTabs.left.length !== 0,
    title: __('menu_STORE_LEFT_TABS') + ` (${groupedTabs.left.length})`,
  })
  browser.contextMenus.update('STORE.STORE_RIGHT_TABS', {
    enabled: groupedTabs.right.length !== 0,
    title: __('menu_STORE_RIGHT_TABS') + ` (${groupedTabs.right.length})`,
  })
  browser.contextMenus.update('STORE.STORE_TWOSIDE_TABS', {
    enabled: groupedTabs.twoSide.length !== 0,
    title: __('menu_STORE_TWOSIDE_TABS') + ` (${groupedTabs.twoSide.length})`,
  })
  browser.contextMenus.update('STORE.STORE_ALL_TABS_IN_ALL_WINDOWS', {
    enabled: windows.length > 1,
  })
  browser.contextMenus.update('STORE.STORE_ALL_TABS_IN_CURRENT_WINDOW', {
github cliffordfajardo / cato / app / plugins / merge-sort-tabs / index.js View on Github external
async function sortAndMergeWindows() {
  const currentWindow = await browser.windows.getCurrent()
  const allWindows = await browser.windows.getAll({populate: true})
  let allTabs = []
  let index = 0

  allWindows.forEach((browserWindow) => {
    browserWindow.tabs.forEach((tab) => {
      allTabs.push({id: tab.id, domain: domain.origin(tab.url)})
    })

    allTabs = sortBy(allTabs, ['domain'])
    allTabs.forEach((tab) => {
      browser.tabs.move(tab.id, {windowId: currentWindow.id, index})
      index += 1
    })
    window.close()
github foray1010 / Popup-my-Bookmarks / src / js / popup / functions / bookmarks.js View on Github external
const thisItemInfo: Object = await getBookmark(itemInfo.id)

    urlList.push(thisItemInfo.url)
  }

  if (!isNewWindow) {
    await Promise.all(
      urlList.map((url: string): Promise => {
        return webExtension.tabs.create({
          url,
          active: false
        })
      })
    )
  } else {
    await webExtension.windows.create({
      url: urlList,
      incognito: isIncognito
    })
  }

  window.close()
}