Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
chrome.windows.create creates new popups when execute multiple times

I have this chrome extension with a browser_action button. When this browser action is clicked, the background script opens a popup as follows

const popup = window.open('popup.html', tab.id, 'menubar=0,innerWidth=900,innerHeight=800');

When the user clicks the browser action multiple times, the popup is recreated each time (I don't get multiple popup windows)

However, now I would like to replace this code with browser.windows.create which as far as I know, is more the extension-way. So I created

browser.windows.create({url: 'popup.html', height: 800, width: 900, type: 'popup'});

This works almost identical, except, when the user clicks the browser action button multiple times I get multiple popup windows, which is not what I want. Is there a way to get same behaviour as `window.open?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's my suggestion (in typescript):

function findTab(tab: chrome.tabs.Tab) {
    return tab.url == "popup.html";
}

// first get all open chrome windows
let windows = await chrome.windows.getAll({populate: true, windowTypes: ["popup"]});

// find a window that has a tab with the url "popup.html"
let myWindow = windows.find(window => window.tabs.some(tab => findTab(tab)));

// find a tab that has the url "popup.html"
let myTab = myWindow?.tabs.find(tab => findTab(tab));

if (myWindow && myTab) {
    // if such tab exists, focus the parent window and the tab
    await chrome.windows.update(myWindow.id, {focused: true});
    await chrome.tabs.update(myTab.id, {active: true});
}
else {
    // open the window and the tab
    await chrome.windows.create({url: "popup.html", type: "popup"});
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda