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:
2025-03-15 00:46:02 -04:00
parent 0f9f6c776d
commit 7c0e44a22f
2 changed files with 49 additions and 3 deletions

17
node.go
View File

@@ -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 {