diff --git a/deno.jsonc b/deno.jsonc index ea9a14f..94b6539 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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", diff --git a/src/browser.ts b/src/browser.ts index 327f7df..de2fd51 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -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. */ diff --git a/src/element_handle.ts b/src/element_handle.ts index 4b541e9..b756c18 100644 --- a/src/element_handle.ts +++ b/src/element_handle.ts @@ -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}`); } } diff --git a/src/page.ts b/src/page.ts index 61e0ca5..ad7876b 100644 --- a/src/page.ts +++ b/src/page.ts @@ -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;