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

161
Visualizações
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 à 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