Skip to content

Commit

Permalink
Merge pull request #11 from lino-levan/feat-page-url
Browse files Browse the repository at this point in the history
feat: url property to page
  • Loading branch information
lino-levan authored Aug 31, 2023
2 parents 2e9b5be + 2cb2754 commit 0fd73cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Browser {
const websocket = new WebSocket(wsUrl);
await websocketReady(websocket);

const page = new Page(targetId, websocket, this);
const page = new Page(targetId, url, websocket, this);
this.pages.push(page);

const celestial = page.unsafelyGetCelestialBindings();
Expand Down
21 changes: 20 additions & 1 deletion src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,29 @@ export class Page {
#id: string;
#celestial: Celestial;
#browser: Browser;
#url: string | undefined;

readonly timeout = 10000;
readonly mouse: Mouse;
readonly keyboard: Keyboard;
readonly touchscreen: Touchscreen;

constructor(id: string, ws: WebSocket, browser: Browser) {
constructor(
id: string,
url: string | undefined,
ws: WebSocket,
browser: Browser,
) {
this.#id = id;
this.#url = url;
this.#celestial = new Celestial(ws);
this.#browser = browser;

this.#celestial.addEventListener("Page.frameNavigated", (e) => {
const { frame } = e.detail;
this.#url = frame.urlFragment ?? frame.url;
});

this.mouse = new Mouse(this.#celestial);
this.keyboard = new Keyboard(this.#celestial);
this.touchscreen = new Touchscreen(this.#celestial);
Expand Down Expand Up @@ -330,6 +342,13 @@ export class Page {
return convertToUint8Array(data);
}

/**
* The current URL of the page
*/
get url() {
return this.#url;
}

/**
* Runs a function in the context of the page until it returns a truthy value.
*/
Expand Down

0 comments on commit 0fd73cf

Please sign in to comment.