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

216
Visualizações
How to detect history state change in a Safari extension?

I've been developing a cross-browser extension (for Chrome, Firefox, Opera, etc) that runs a script every time the user goes to a new page on Youtube. Since Youtube uses the History API's pushState to navigate to a new page, injecting the script declaratively only works when a page is reloaded or the URL is explicitly entered into the address bar. To get around this, I used onHistoryStateUpdated from the webNavigation API to inject the script programmatically (as explained here).

manifest.json:

...
"permissions": ["webNavigation", "https://*.youtube.com/*"]
...

background.js:

chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
chrome.tabs.executeScript(details.tabId, {file: "/content.js"});
}

I want to port my extension to Safari, but according to their documentation, onHistoryStateUpdated is not supported. Are there any alternative ways to detect changes for pushState in Safari?

P.S. I hope I'm explaining this well enough, since this is my first question on Stack Exchange. Thanks so much in advance!

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

0

After searching through the Mozilla Development Network (MDN), I found a solution (linked here) for my extension that works with Safari. It involves detecting tab changes instead of history state changes, shown below.

manifest.json:

...
"permissions": ["https://*.youtube.com/*"]
...

background.js:

function handleUpdated(tabId, changeInfo) {
if (changeInfo.url) {
browser.tabs.executeScript({file: "/content.js"});
}
}
browser.tabs.onUpdated.addListener(handleUpdated);

Note: In order to detect tab changes for other websites, the other websites need to be added to the host permissions list in the manifest file.

Hope this helps others in their extension development. Thanks!

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