Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!