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

158
Vistas
chrome.declarativeContent API's RequestContentScript permission does not work after restart of the browser/ closing and reopening site

I am trying to dynamically get permission to certain sites (Eg amazon.fr) using optional permission and once I get the permission I am injecting some JS into the sites for which I requested permissions using declarative content API's RequestContentScript function.

All this works fine for the first time till I either close the browser or close all the pages where scripts are injected initially. But after the page inject JS is not injected into those sites. When I check the permission and sites of the extension I see all the permission I requested optionally are still present via the get permission API.

The background js code I am using to request permission and inject scripts is as follow

const conditions = [];
chrome.permissions.request({
  permissions: ['declarativeContent'],
  origins:['https://www.amazon.fr/'],
}, (granted) => {
  console.log({ granted });
  if (granted) {
     conditions.push(new chrome.declarativeContent.PageStateMatcher({
        pageUrl: { hostEquals: 'www.amazon.fr', schemes: ['https'] },
        css: ['div'],
      }));
    const rule2 = {
          conditions,
          actions: [
         new chrome.declarativeContent.RequestContentScript({ 
         js: ['page_injects/index.js'], 
         css: ['page_injects/index.css'] })],
    };
chrome.declarativeContent.onPageChanged.removeRules(undefined,() => {
           chrome.declarativeContent.onPageChanged.addRules([rule2]);
         });
    console.log('chrome.declarativeContent.onPageChanged.addRules done');
  }
});


Since this works for the first time I am not sure what could be issue in having the same behavior the second time and after.

Any tips on how to proceed with this?

I used this SO question to arrive at injecting scripts optionally.

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