Skip to content

Commit

Permalink
Add geolocation feature (Page.setGeolocation)
Browse files Browse the repository at this point in the history
Fixes #79.
  • Loading branch information
zploskey committed Sep 8, 2018
1 parent 7a87013 commit 25003f4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/js/src/Page.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,41 @@ external setCacheEnabled: (t, ~enabled: bool) => Js.Promise.t(unit) = "";
[@bs.send]
external setDefaultNavigationTimeout: (t, ~timeout: float) => unit = "";

module GeolocationOptions = {
[@bs.deriving abstract]
type t = {
latitude: float,
longitude: float,
[@bs.optional]
accuracy: float,
};

/** Create a `GeolocationOptions` object.
When passed to `Page.setGeolocation` the following conditions must be met or
an error will be thrown:
- `latitude` must be in the range -90. to 90 degrees.
- `longitude` must be in the range -180. to 180 degrees.
- `accuracy` (optional) must be >= 0.
*/
let make = t;
};

/** Set the page's geolocation.
```
let loc = Geolocation.make(~latitude=33.0, ~longitude=44.0, ());
page->Page.setGeolocation(loc);
```
You'll probably need to use `BrowserContext.overridePermissions` to grant
permission for the page to read its geolocation.
*/
[@bs.send]
external setGeolocation:
(t, ~options: GeolocationOptions.t) => Js.Promise.t(unit) =
"";

/** Set whether to enable JavaScript on the page. */
[@bs.send]
external setJavaScriptEnabled: (t, ~enabled: bool) => Js.Promise.t(unit) = "";
Expand Down

0 comments on commit 25003f4

Please sign in to comment.