Skip to content

Commit

Permalink
Merge branch 'main' into ext
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan authored Oct 7, 2024
2 parents b90ad2d + 041b9c5 commit c6e2d63
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "@astral/astral",
"version": "0.4.7",
"version": "0.4.8",
"exports": {
".": "./mod.ts",
"./ext/crawler": "./ext/crawler.ts"
},

},
"tasks": {
// The task to automatically generate `./src/celestial.ts`
"bind": "deno run -A ./bindings/_tools/generate/mod.ts && deno fmt",
Expand Down
7 changes: 7 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export class Browser {
return this.#celestial;
}

/**
* Disconnects the browser from the websocket connection. This is useful if you want to keep the browser running but don't want to use it anymore.
*/
async disconnect() {
await this.#celestial.close();
}

/**
* Closes the browser and all of its pages (if any were opened). The Browser object itself is considered to be disposed and cannot be used anymore.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/element_handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class ElementHandle {
options?.timeout || this.#page.timeout,
);
} catch {
throw new Error("Unable to get element from selector");
throw new Error(`Unable to get element from selector: ${selector}`);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,15 @@ export class Page extends EventTarget {
return this.close();
}

//TODO(@lowlighter): change "query" by "request" https://github.com/denoland/deno/issues/14668
async #validateRequest({ request }: Fetch_requestPausedEvent["detail"]) {
const { protocol, host, href } = new URL(request.url);
if (host) {
const { state } = await Deno.permissions.query({ name: "net", host });
const { state } = await Deno.permissions.request({ name: "net", host });
return (state === "granted");
}
if (protocol === "file:") {
const path = fromFileUrl(href);
const { state } = await Deno.permissions.query({ name: "read", path });
const { state } = await Deno.permissions.request({ name: "read", path });
return (state === "granted");
}
return true;
Expand Down

0 comments on commit c6e2d63

Please sign in to comment.