Add viewport dimensions and dark mode support
This commit introduces optional viewport dimensions and dark mode support to the PlayWrightBrowserOptions struct and its usage. It ensures more control over browser display settings and improves flexibility when configuring browser contexts. Additionally, visibility checking logic in SetHidden was refined to avoid redundant operations.
This commit is contained in:
17
node.go
17
node.go
@@ -87,8 +87,21 @@ func (n node) ForEach(selector string, fn func(Node) error) error {
|
||||
}
|
||||
|
||||
func (n node) SetHidden(val bool) error {
|
||||
_, err := n.locator.Evaluate(fmt.Sprintf(`(element) => element.hidden = %t;`, val), nil)
|
||||
return err
|
||||
visible, err := n.locator.IsVisible()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error checking visibility: %w", err)
|
||||
}
|
||||
if visible == !val {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set the hidden property
|
||||
_, err = n.locator.Evaluate(fmt.Sprintf(`(element) => element.hidden = %t;`, val), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error setting hidden property: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func escapeJavaScript(s string) string {
|
||||
|
Reference in New Issue
Block a user