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

285
Visualizações
I want to wait until the Shadow DOM elements are loaded

I am developing a Chrome extension.

I would like to develop a feature that when you Hover an element on the page, a frame appears around the element, but it doesn't work with the Shadow DOM element.

I believe this is due to the fact that the shadow dom element is not loaded on the page at the time the load event fires.

This is especially true for pages with nested shadow doms. ex.) https://developer.servicenow.com/dev.do

However, I do not know how to detect that the entire page, including the shadow dom, has finished loading.

Please let me know if you know of a solution.

function addAttribute(e) {
  const el = e.path || (e.composedPath && e.composedPath());
  el.setAttribute('style', "outline: solid 4px !important");
}

function removeAttribute(e) {
  const el = e.path || (e.composedPath && e.composedPath());
  el.removeAttribute('style', "outline: solid 4px !important");
}

function addEventListenerToShadow(root) {
  const tw = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
  
  do {
    const currentNode = tw.currentNode;
    if (currentNode instanceof ShadowRoot) continue;
    if (currentNode.shadowRoot) {
      currentNode.shadowRoot.addEventListener('mouseover', addAttribute)
      currentNode.shadowRoot.addEventListener('mouseout', removeAttribute)
      addEventListenerToShadow(currentNode.shadowRoot);
    }
  } while (tw.nextNode());
}

window.onload = addEventListenerToShadow(document.body);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

(nested) shadowDOM are (DOM) children entering your class-room.

Only when you know how many there will come you know when the last one entered.

That means each (shadow) DOM/Element should notify it will come to the main application.

And the application then processes/counts down each "arrived" DOM Child/shadowDOM

The connectedCallback fires on the opening TAG of your Custom Element

So that is the appropriate time to send a CustomEvent I_WILL_COME to the application.

BUT... in your use-case you do not have control over what components do. So the only escape is just wait N seconds and consider your page loaded.

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