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

265
Visualizações
How can you change the document object of inactive tabs?

My goal is to write a browser extension, that can rename the titles of multiple tabs at once. Or to be more precise: append a string at the start of each title.

Do you have any ideas, how that could be achieved?


Here are some of my attempts so far:

This code would allow me(with the tabs permission enabled and without the activeTab permission) to get the tabs objects of all the tabs of the current window:

chrome.tabs && chrome.tabs.query({
                currentWindow: true
            }, tabs => {
                for (let i = 0; i < tabs.length; i++) {
                    chrome.tabs.sendMessage(
                        tabs[i].id || 0,
                        {}
                    )
                }
            });

for each "tabs" object (which contains a tabs.title) I could perhaps use the sendMessage function? That was the initial idea. But I'm not sure how I would do that or if that even makes sense.


In general, I'm wondering if the title of each tab needs to be changed by setting document.title.

That could potentially be done via a script. I have seen this solution elsewhere:

chrome.tabs.executeScript({
                code: 'document.title=' + JSON.stringify(newTitle)
            });

But I also need to specify for which tab the document.title needs to be changed.

And I'm using Manifest version 3. And the executeScript function was deprecated. Instead there is now a scripting api with it's own permission. It contains an executeScript function:

chrome.scripting.executeScript(
  injection: ScriptInjection,
  callback?: function,
)

whereby the ScriptInjection has a target. Which I could set to tabs[i].id inside the for loop shown above.

Perhaps like this?:

chrome.tabs && chrome.tabs.query({
                currentWindow: true
            }, tabs => {
                for (let i = 0; i < tabs.length; i++) {
                    chrome.scripting.executeScript(
                        injection: () => {target: { tabId: tabs[i].id }}, files: [renameTitleScript.js]}
                    )
                }
            });

I don't like that I need a separate file with a script. Instead of just having a function in the same scope that lets me pass the new title. And since I don't know whether I'm even on the correct path, I'm hoping you can give me some suggestions.

about 4 years ago · Juan Pablo Isaza
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