1

Create an Engine instance:

engine = EngineFactory.Create(new EngineOptions.Builder
            {
                RenderingMode = RenderingMode.HardwareAccelerated,
                UserDataDirectory = folderBrowser,
                LicenseKey = lic,
                
                UserAgent = UA,
                GoogleApiKey = "input key",
                GoogleDefaultClientId = "put client id",
                GoogleDefaultClientSecret = "put secret"
            }
            .Build());

Grant permission for all permission requests:

engine.Permissions.RequestPermissionHandler =
    new Handler<RequestPermissionParameters, RequestPermissionResponse>(p =>
    {
            return RequestPermissionResponse.Grant();
    });

When I check geolocation in https://browserleaks.com/geo or https://geolocation.com/ I see that the geolocation permissions are granted and I see my actual coordinates: enter image description here

But if I open other web site like https://google.com or https://yandex.ru - I see that permission - denied and geolocation does not work. To check permission I create the following JS:

string perm = @"
var res;
var test = function(e){res=e};

navigator.permissions.query({ name: 'geolocation' }).then(result => {
      test(result.state)
})
res
";

When the Google or Yandex pages are downloaded, I execute this JS for check so:

string permiss = I.ActiveTab.browser.MainFrame.ExecuteJavaScript<string>(perm).Result;
string res = I.ActiveTab.browser.MainFrame.ExecuteJavaScript<string>("res").Result;

For https://browserleaks.com/geo or https://geolocation.com/ I have the "res" variable all time granted, but in Google or Yandex - I have "res" all time denied.

Why so? If I do not create filtr for URL when I create "engine.Permissions.RequestPermissionHandler".

I see that navigate not to page https://browserleaks.com/geo, DotNetBrowser does not go inside this code:

new Handler<RequestPermissionParameters, RequestPermissionResponse>(p =>
    {
            return RequestPermissionResponse.Grant();
    });

and in page all permissions are denied. What do I need to do to go into RequestPermissionHandler every time for every web page?

Vladimir
  • 1
  • 1
  • 23
  • 30

1 Answers1

1

problem that geolocation not work in same page, becouse some page not send navigator.geolocation.getCurrentPosition(success, error, options); if navigator.permissions.query({ name: 'geolocation' }) - return denied and not send ask permission for this page, and in DotNetBrowser before sending request all permission is denied.

Now I make so string with js:

public static string askpermissiongeo = @"
var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log(`Latitude : ${crd.latitude}`);
  console.log(`Longitude: ${crd.longitude}`);
  console.log(`More or less ${crd.accuracy} meters.`);
}

function error(err) {
  console.warn(`ERROR(${err.code}): ${err.message}`);
}


window.onload = navigator.geolocation.getCurrentPosition(success, error, options);
";

and inject this code, when need turn on geolocation in some page:

b.InjectJsHandler = new Handler<InjectJsParameters>(args =>
    {
         IJsObject askperm = args.Frame.ExecuteJavaScript<IJsObject>(askpermissiongeo).Result;
    });

after this manipulation DotNetBrowser go to code:

engine.Permissions.RequestPermissionHandler =
    new Handler<RequestPermissionParameters, RequestPermissionResponse>(p =>
    {
        
            return RequestPermissionResponse.Grant();
        
    });

and all work