Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element.ShadowRoot returns error when ShadowRoots is empty #788

Merged
merged 4 commits into from Jan 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions element.go
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/go-rod/rod/lib/utils"
)

var (
// ErrNoShadowRoot is calling ShadowRoot on an Element with no shadow root
ErrNoShadowRoot = errors.New("element has no shadow root")
ysmood marked this conversation as resolved.
Show resolved Hide resolved
)

// Element implements these interfaces
var _ proto.Client = &Element{}
var _ proto.Contextable = &Element{}
Expand Down Expand Up @@ -402,6 +407,9 @@ func (el *Element) ShadowRoot() (*Element, error) {
}

// though now it's an array, w3c changed the spec of it to be a single.
if len(node.ShadowRoots) == 0 {
return nil, ErrNoShadowRoot
}
id := node.ShadowRoots[0].BackendNodeID

shadowNode, err := proto.DOMResolveNode{BackendNodeID: id}.Call(el)
Expand Down