diff --git a/common/browser_context.go b/common/browser_context.go index 3e2257dce..1ee7ebcc7 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -295,6 +295,16 @@ func (b *BrowserContext) SetDefaultTimeout(timeout int64) { func (b *BrowserContext) SetGeolocation(g *Geolocation) error { b.logger.Debugf("BrowserContext:SetGeolocation", "bctxid:%v", b.id) + if g.Longitude < -180 || g.Longitude > 180 { + return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, g.Longitude) + } + if g.Latitude < -90 || g.Latitude > 90 { + return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, g.Latitude) + } + if g.Accuracy < 0 { + return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, g.Accuracy) + } + b.opts.Geolocation = g for _, p := range b.browser.getPages() { if err := p.updateGeolocation(); err != nil { diff --git a/common/browser_context_options.go b/common/browser_context_options.go index 4decfbaff..56e5b6215 100644 --- a/common/browser_context_options.go +++ b/common/browser_context_options.go @@ -41,16 +41,6 @@ func (g *Geolocation) Parse(ctx context.Context, sopts sobek.Value) error { //no } } - if newgl.Longitude < -180 || newgl.Longitude > 180 { - return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, newgl.Longitude) - } - if newgl.Latitude < -90 || newgl.Latitude > 90 { - return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, newgl.Latitude) - } - if newgl.Accuracy < 0 { - return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, newgl.Accuracy) - } - *g = newgl return nil