Closed Bug 1470545 Opened 6 years ago Closed 6 years ago

Add a "shadowrootattached" event for devtools.

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: emilio, Assigned: emilio)

References

Details

Attachments

(1 file)

      No description provided.
Since devtools also can access closed shadow roots via openOrClosedShadowRoot,
they can add the event listener to the shadow root to handle nested shadows
like:

function onShadowRootAttached(e) {
  e.target.openOrClosedShadowRoot.addEventListener(
    "shadowrootattached", onShadowRootAttached);

  // Other stuff...
}

document.addEventListener(
  "shadowrootattached", onShadowRootAttached);

I didn't bother to add tests for the event itself since this is going to get
tested in bug 1449333, but I can look into writing a chrome mochitest if you
want.
Attachment #8987171 - Flags: review?(bugs)
Why the need to add more listeners? Adding listener to chrome event handler and then using composedTarget should be fine.
Hmm, when you have nested closed shadow roots, isn't the composed target when the event handler on the document fires the topmost one? I don't think you can reach to the actual shadow host in that case, can you?

Anyway, if there's a way to do this without those nested listeners that's great.
Ohh, nevermind, composedTarget isn't retargeted, and is chromeonly.
(So, yes, would work)
.target is the topmost one. 
.composedTarget is ChromeOnly thing, https://searchfox.org/mozilla-central/rev/9a3f8590f807d449e790c8ba0e39eb14f41066d8/dom/events/Event.cpp#287 returning basically the deepest non-NAC target.
Attachment #8987171 - Flags: review?(bugs) → review-
Depends on: 1470930
Comment on attachment 8987171 [details]
Bug 1470545: Add chromeonly "shadowrootattached" event for devtools. r=smaug

I updated the Phabricator a while ago, forgot to update the flag here.
Attachment #8987171 - Flags: review- → review?(bugs)
Comment on attachment 8987171 [details]
Bug 1470545: Add chromeonly "shadowrootattached" event for devtools. r=smaug

Olli Pettay [:smaug] has approved the revision.

https://phabricator.services.mozilla.com/D1777
Attachment #8987171 - Flags: review+
Pushed by emilio@crisal.io:
https://hg.mozilla.org/integration/mozilla-inbound/rev/65df1f8bb3cb
Add chromeonly "shadowrootattached" event for devtools. r=smaug
https://hg.mozilla.org/mozilla-central/rev/65df1f8bb3cb
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in before you can comment on or make changes to this bug.