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

127
Visualizações
Browser extension to stop particular page elements from loading

After some googling and looking at tutorials, I have code along these lines:

File: background.js:

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status == 'complete' && tab.active) {

    chrome.tabs.executeScript(tab.ib, {
        file: 'inject.js'
    });
  }
})

File: inject.js

(function() {

    function remove_by_class(className) {
        var elem = document.getElementsByClassName(className)[0];
        elem.parentNode.removeChild(elem);
    }
    
    function remove_by_title(itemTitle) {
        var elem = document.querySelector('[title = itemTitle]');
        elem.parentNode.removeChild(elem);
    }
    
    if (url.includes('SOME_URL_SUBSTRING')){
        remove_by_class('CLASS_NAME');
        remove_by_title('ITEM_TITLE');
    }
    
})();

This removes certain elements, usually a second or two after I see them load in. And if I understand correctly, it can only remove elements from the page as it 'initially' exists, when it is first loaded - elements created later (by future Javascript actions on the page) are unaffected, because my extension's code is only injected & executed once.

What I'm looking for instead is some sort of 'always-on' extension that proactively watches for the loading of certain elements. Basically, I want to have a function which is called every time an HTML element is loaded/created in the page, and only allow the element to actually be placed if the function returns 'true'.

What is the easiest way to accomplish something like this?

EDIT: as an example, say I wanted to block the YouTube logo (class name style-scope ytd-topbar-logo-renderer from loading). I guess I would like a MWE that stops it from loading.

(For context: I am completely new to both Chrome extensions in particular and Javascript in general, but otherwise somewhat familiar with programming. I am mostly just curious/playing around right now, but there is a vague goal of making a kind of 'productivity tool' for myself, allowing me to use Facebook, Youtube etc for exactly what I need them for, with distracting or extraneous (to me) elements, such as Recommended Videos, redacted.)

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