Add UseLocalOnly option to Playwright connection logic

Introduced the `UseLocalOnly` option to prevent connections to a remote Playwright server and enforce usage of the local server. Updated relevant connection logic to respect this new option.
This commit is contained in:
2025-10-12 00:10:58 -04:00
parent afa0238758
commit e32a6fa791

View File

@@ -63,6 +63,9 @@ type PlayWrightBrowserOptions struct {
// DontLaunchOnConnectFailure will, if set, not launch the browser if the connection to the PlayWright server, // DontLaunchOnConnectFailure will, if set, not launch the browser if the connection to the PlayWright server,
// and return an error if the connection fails. // and return an error if the connection fails.
DontLaunchOnConnectFailure bool DontLaunchOnConnectFailure bool
// UseLocalOnly will, if set, not connect to the PlayWright server, and instead use the local PlayWright server.
UseLocalOnly bool
} }
func cookieToPlaywrightOptionalCookie(cookie Cookie) playwright.OptionalCookie { func cookieToPlaywrightOptionalCookie(cookie Cookie) playwright.OptionalCookie {
@@ -119,6 +122,9 @@ func NewPlayWrightBrowser(opts ...PlayWrightBrowserOptions) (Browser, error) {
if o.PlayWrightServerAddress != "" { if o.PlayWrightServerAddress != "" {
opt.PlayWrightServerAddress = o.PlayWrightServerAddress opt.PlayWrightServerAddress = o.PlayWrightServerAddress
} }
if o.DontLaunchOnConnectFailure {
opt.DontLaunchOnConnectFailure = true
}
opt.ShowBrowser = o.ShowBrowser opt.ShowBrowser = o.ShowBrowser
} }
@@ -165,7 +171,7 @@ func NewPlayWrightBrowser(opts ...PlayWrightBrowserOptions) (Browser, error) {
var browser playwright.Browser var browser playwright.Browser
var launch = true var launch = true
if opt.PlayWrightServerAddress != "" { if opt.PlayWrightServerAddress != "" && !opt.UseLocalOnly {
launch = false launch = false
slog.Info("connecting to playwright server", "address", opt.PlayWrightServerAddress) slog.Info("connecting to playwright server", "address", opt.PlayWrightServerAddress)
var timeout float64 = 30000 var timeout float64 = 30000