mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-03 14:50:02 +00:00
LibWeb: Add Internals.getShadowRoot(element)
This lets you access closed shadow roots from JavaScript, even though they're not normally accessible to JavaScript. This can be used to poke into UA shadow roots in tests.
This commit is contained in:
parent
59162342e6
commit
1402c143a9
Notes:
github-actions[bot]
2025-08-07 20:17:29 +00:00
Author: https://github.com/awesomekling
Commit: 1402c143a9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5767
5 changed files with 22 additions and 0 deletions
|
@ -325,4 +325,9 @@ String Internals::dump_display_list()
|
|||
return window().associated_document().dump_display_list();
|
||||
}
|
||||
|
||||
GC::Ptr<DOM::ShadowRoot> Internals::get_shadow_root(GC::Ref<DOM::Element> element)
|
||||
{
|
||||
return element->shadow_root();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ public:
|
|||
|
||||
String dump_display_list();
|
||||
|
||||
GC::Ptr<DOM::ShadowRoot> get_shadow_root(GC::Ref<DOM::Element>);
|
||||
|
||||
private:
|
||||
explicit Internals(JS::Realm&);
|
||||
|
||||
|
|
|
@ -54,4 +54,8 @@ interface Internals {
|
|||
readonly attribute boolean headless;
|
||||
|
||||
DOMString dumpDisplayList();
|
||||
|
||||
// Returns the shadow root of the element, if it has one, even if it's not normally accessible to JS.
|
||||
ShadowRoot? getShadowRoot(Element element);
|
||||
|
||||
};
|
||||
|
|
2
Tests/LibWeb/Text/expected/Internals/getShadowRoot.txt
Normal file
2
Tests/LibWeb/Text/expected/Internals/getShadowRoot.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
null
|
||||
[object ShadowRoot]
|
9
Tests/LibWeb/Text/input/Internals/getShadowRoot.html
Normal file
9
Tests/LibWeb/Text/input/Internals/getShadowRoot.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!doctype html>
|
||||
<script src="../include.js"></script>
|
||||
<input id="myInput">
|
||||
<script>
|
||||
test(() => {
|
||||
println(myInput.shadowRoot);
|
||||
println(internals.getShadowRoot(myInput));
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue