Question about Shadow DOM

Discussions about the development and maturation of the platform code (UXP).
Warning: may contain highly-technical topics.

Moderators: trava90, athenian200

User avatar
dim22
Moongazer
Moongazer
Posts: 9
Joined: 2024-03-13, 04:52

Question about Shadow DOM

Post by dim22 » 2024-09-02, 18:07

Hi! Maybe I'm not addressing the topic, but since I can't create a topic, I'll ask here.
Is there an option in Pale Moon to access a closed shadow-root like in chrome or firefox "openOrClosedShadowRoot"?
Here is an html example:

Code: Select all

<!DOCTYPE html>
<html lang="ru">
	<head></head>
	<body>
		<div id="example">
			<div>
				#shadow-root (close)
				<iframe src="Another domain">
					#document
					<!DOCTYPE html>
					<html lang="en-US" dir="ltr">
						<head></head>
						<body>
							#shadow-root (close)
							<div>
								<div id="content"><div>
							<div>
						</body>
					</html>
				</iframe>
			<div>
		</div>
	</body>
</html>
In Firefox, using an extension, you can do this like this:
content.document.getElementById("example")
.firstChild.openOrClosedShadowRoot.firstChild.contentDocument
.body.openOrClosedShadowRoot.querySelector("#content")
But I can't figure out how to do this in Pale Moon.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 37767
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Question about Shadow DOM

Post by Moonchild » 2024-09-02, 18:30

The whole point of closing a DOM tree (making it Shadow DOM) is that it becomes isolated and can no longer be accessed from the initiating document, at least that is always how I understood it.
The shadow tree still has access to the doc but the doc no longer has access to the shadow tree (hence the name Shadow DOM - it's a dark structure).
You can only access a closed Shadow DOM by the reference returned by attachShadow. You can't access it by reference from a document element.
Side note: Browser-native shadow trees are closed and don't expose a reference because you didn't create them. There’s no way at all to access those.
"A dead end street is a place to turn around and go into a new direction" - Anonymous
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
dim22
Moongazer
Moongazer
Posts: 9
Joined: 2024-03-13, 04:52

Re: Question about Shadow DOM

Post by dim22 » 2024-09-02, 18:49

Moonchild wrote:
2024-09-02, 18:30
There’s no way at all to access those.
It is a pity that this is not possible in Pale Moon, when chrome and firefox have openOrClosedShadowRoot for this

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 37767
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Question about Shadow DOM

Post by Moonchild » 2024-09-02, 19:32

dim22 wrote:
2024-09-02, 18:49
when chrome and firefox have openOrClosedShadowRoot for this
Maybe you missed the point... Shadow DOM being Shadow DOM is by design inaccessible. Having such a function would make the ENTIRE premise behind Shadow DOM irrelevant because in that case you may as well only have "light trees".

But what I was saying in what you quoted was that browser-native shadow DOM is entirely inaccessible, i.e. Shadow DOM resulting from code that isn't part of the content document (e.g. attached by an extension or native browser components). i.e. since you didn't attach it yourself, you won't ever be able to have a reference to it.
"A dead end street is a place to turn around and go into a new direction" - Anonymous
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite