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

159
Visualizações
chrome extension works on refresh/on land but not on 'internal navigation'

So simply when I land a page on youtube which starts with w* (meaning that a specific video with its ID) I'm firing alert(url) and it works however it only works when I land that page from the URL and/or on refresh. What I'm trying to achieve is to fire that alert when navigating to that page (watch?=...) FROM another youtube page meaning that I'm navigating internally.

as an example: www.youtube.com -> this is the landing page of youtube I click on a video and I navigate to: www.youtube.com/watch?=aiFUQ9981Qk

this DOES NOT trigger my alert HOWEVER when I refresh, it does trigger. how do i trigger even when i navigate 'FROM' 'WITHIN' youtube ? Any input would be appreciated. manifest and Content.js attached below...

manifest.json

{
    "manifest_version": 2,
    "name": "youtest",
    "version": "1.0.0",
    "content_scripts": [
        {
            "matches": ["https://*.youtube.com/watch?*"],
            "js": ["Content.js"]
        }
    ]
}

Content.js

console.log(window.location.href);
alert(window.location.href);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

function runScript() {
    if (window.location.href.indexOf('watch?') > -1) {
        alert('this is a video');
        let videoID = window.location.href.slice(
            window.location.href.lastIndexOf('/')
        );
        alert(videoID);
    } else {
        alert('not a video');
    }
}

document.addEventListener('yt-navigate-start', runScript);
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