diff --git a/internal/version/VERSION b/internal/version/VERSION index b38d6c9c..4d5604a8 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2503032127 +v5.0.0+2503032140 diff --git a/pkg/uixt/browser_device.go b/pkg/uixt/browser_device.go index cbd78ffa..936dce8a 100644 --- a/pkg/uixt/browser_device.go +++ b/pkg/uixt/browser_device.go @@ -11,38 +11,34 @@ import ( ) type BrowserDevice struct { - BrowserId string `json:"browser_id,omitempty" yaml:"browser_id,omitempty"` - LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"` + Options *option.BrowserDeviceOptions } -type BrowserDeviceOption func(*BrowserDevice) - -func WithBrowserId(serial string) BrowserDeviceOption { - return func(device *BrowserDevice) { - device.BrowserId = serial - } -} - -func NewBrowserDevice(options ...BrowserDeviceOption) (device *BrowserDevice, err error) { - device = &BrowserDevice{} - for _, option := range options { - option(device) +func NewBrowserDevice(opts ...option.BrowserDeviceOption) (device *BrowserDevice, err error) { + options := &option.BrowserDeviceOptions{} + for _, option := range opts { + option(options) } - if device.BrowserId == "" { + if options.BrowserID == "" { browserInfo, err := CreateBrowser(3600) if err != nil { log.Error().Err(err).Msg("failed to create browser") return nil, err } - device.BrowserId = browserInfo.ContextId + options.BrowserID = browserInfo.ContextId } + device = &BrowserDevice{ + Options: options, + } + log.Info().Str("browserID", device.Options.BrowserID).Msg("init browser device") + return device, nil } func (dev *BrowserDevice) UUID() string { - return dev.BrowserId + return dev.Options.BrowserID } func (dev *BrowserDevice) Setup() error { @@ -50,7 +46,7 @@ func (dev *BrowserDevice) Setup() error { } func (dev *BrowserDevice) LogEnabled() bool { - return dev.LogOn + return dev.Options.LogOn } func (dev *BrowserDevice) Teardown() error { diff --git a/pkg/uixt/option/browser.go b/pkg/uixt/option/browser.go new file mode 100644 index 00000000..92dee538 --- /dev/null +++ b/pkg/uixt/option/browser.go @@ -0,0 +1,14 @@ +package option + +type BrowserDeviceOptions struct { + BrowserID string `json:"browser_id,omitempty" yaml:"browser_id,omitempty"` + LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"` +} + +type BrowserDeviceOption func(*BrowserDeviceOptions) + +func WithBrowserID(serial string) BrowserDeviceOption { + return func(device *BrowserDeviceOptions) { + device.BrowserID = serial + } +} diff --git a/server/context.go b/server/context.go index 48af2b3a..92bdb9f3 100644 --- a/server/context.go +++ b/server/context.go @@ -66,7 +66,7 @@ func (p RouterBaseMethod) GetDevice(c *gin.Context) (device uixt.IDevice, err er return } case "browser": - device, err = uixt.NewBrowserDevice(uixt.WithBrowserId(serial)) + device, err = uixt.NewBrowserDevice(option.WithBrowserID(serial)) if err != nil { RenderErrorInitDriver(c, err) return