@@ -162,7 +162,46 @@ public override async Task<IResponse> ReloadAsync(NavigationOptions options)
162162 public override Task < IFrame > WaitForFrameAsync ( Func < IFrame , bool > predicate , WaitForOptions options = null ) => throw new NotImplementedException ( ) ;
163163
164164 /// <inheritdoc />
165- public override Task SetGeolocationAsync ( GeolocationOption options ) => throw new NotImplementedException ( ) ;
165+ public override async Task SetGeolocationAsync ( GeolocationOption options )
166+ {
167+ if ( options == null )
168+ {
169+ throw new ArgumentNullException ( nameof ( options ) ) ;
170+ }
171+
172+ var longitude = options . Longitude ;
173+ var latitude = options . Latitude ;
174+ var accuracy = options . Accuracy ;
175+
176+ if ( longitude < - 180 || longitude > 180 )
177+ {
178+ throw new ArgumentException ( $ "Invalid longitude '{ longitude } ': precondition -180 <= LONGITUDE <= 180 failed.") ;
179+ }
180+
181+ if ( latitude < - 90 || latitude > 90 )
182+ {
183+ throw new ArgumentException ( $ "Invalid latitude '{ latitude } ': precondition -90 <= LATITUDE <= 90 failed.") ;
184+ }
185+
186+ if ( accuracy < 0 )
187+ {
188+ throw new ArgumentException ( $ "Invalid accuracy '{ accuracy } ': precondition 0 <= ACCURACY failed.") ;
189+ }
190+
191+ var coordinates = new WebDriverBiDi . Emulation . GeolocationCoordinates ( ( double ) longitude , ( double ) latitude )
192+ {
193+ Accuracy = ( double ? ) accuracy ,
194+ } ;
195+
196+ var commandParameters = new WebDriverBiDi . Emulation . SetGeolocationOverrideCoordinatesCommandParameters
197+ {
198+ Coordinates = coordinates ,
199+ } ;
200+
201+ commandParameters . Contexts . Add ( BidiMainFrame . BrowsingContext . Id ) ;
202+
203+ await BidiMainFrame . BrowsingContext . Session . Driver . Emulation . SetGeolocationOverrideAsync ( commandParameters ) . ConfigureAwait ( false ) ;
204+ }
166205
167206 /// <inheritdoc />
168207 public override Task SetJavaScriptEnabledAsync ( bool enabled ) => throw new NotImplementedException ( ) ;
0 commit comments