Esempio n. 1
0
        /// <inheritdoc cref="IBrowserContext.SetGeolocationAsync(GeolocationOption)"/>
        public Task SetGeolocationAsync(GeolocationOption geolocation = null)
        {
            if (geolocation != null)
            {
                VerifyGeolocation(geolocation);
            }

            Options.Geolocation = geolocation;
            return(_delegate.SetGeolocationAsync(geolocation));
        }
        /// <inheritdoc cref="IBrowserContextDelegate.SetGeolocationAsync(GeolocationOption)"/>
        public async Task SetGeolocationAsync(GeolocationOption geolocation)
        {
            var request = new EmulationSetGeolocationOverrideRequest();

            if (geolocation != null)
            {
                request.Accuracy  = geolocation.Accuracy;
                request.Latitude  = geolocation.Latitude;
                request.Longitude = geolocation.Longitude;
            }

            foreach (Page page in await BrowserContext.GetPagesAsync().ConfigureAwait(false))
            {
                await((ChromiumPage)page.Delegate).Client.SendAsync(request).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        private void VerifyGeolocation(GeolocationOption geolocation)
        {
            if (geolocation.Longitude < -180 || geolocation.Longitude > 180)
            {
                throw new ArgumentException($"Invalid longitude '{geolocation.Longitude}': precondition -180 <= LONGITUDE <= 180 failed.");
            }

            if (geolocation.Latitude < -90 || geolocation.Latitude > 90)
            {
                throw new ArgumentException($"Invalid latitude '{geolocation.Latitude}': precondition -90 <= LONGITUDE <= 90 failed.");
            }

            if (geolocation.Accuracy < 0)
            {
                throw new ArgumentException($"Invalid accuracy '{geolocation.Accuracy}': precondition 0 <= LONGITUDE failed.");
            }
        }
Esempio n. 4
0
 /// <inheritdoc />
 public Task SetGeolocationAsync(GeolocationOption geolocation) => throw new NotImplementedException();
Esempio n. 5
0
 /// <inheritdoc cref="IBrowserContext.SetGeolocationAsync(GeolocationOption)"/>
 public Task SetGeolocationAsync(GeolocationOption geolocation)
 => _delegate.SetGeolocationAsync(geolocation);