Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
Add listener for subpage change in SPA

I want to get innerHTML of a current video on youtube. The code below doesn't work on youtube, because changing subpages doesn't cause reload of whole page (when it does, the code works well). After every video change the innerHTML from first visited video is printed in console. The only way to get the current one is to click f5. How can I rewrite the code to make it work?

manifest.json

  ...
  "background": {
    "service_worker": "background.js"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["index.js"]
    }
  ],
  "permissions": ["activeTab", "scripting", "tabCapture", "storage", "tabs"],
  ...

background.js

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  const regex = /.*youtube.com\/watch\?.*/gm;

  if (changeInfo.status === "complete" && !!tab.url.match(regex)) {
    chrome.tabs.sendMessage(tabId, {
      message: "NEW_VIDEO"
    });
  }
});

index.js

chrome.runtime.onMessage.addListener((request) => {
  if (request.message === "NEW_VIDEO") {
    console.log(document.documentElement.innerHTML);
  }
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda