Skip to main content
Module

x/astral/mod.ts>Page

A high-level puppeteer/playwright-like library for Deno
Latest
class Page
extends EventTarget
Re-export
import { Page } from "https://deno.land/x/astral@0.3.5/mod.ts";

Page provides methods to interact with a single tab in the browser

Constructors

new
Page(
id: string,
url: string | undefined,
browser: Browser,
options: SandboxOptions,
)

Properties

readonly
keyboard: Keyboard
readonly
mouse: Mouse
readonly
timeout: number
readonly
touchscreen: Touchscreen
readonly
url: string | undefined

The current URL of the page

Methods

$(selector: string): Promise<ElementHandle | null>

Runs document.querySelector within the page. If no element matches the selector, the return value resolves to null.

$$(selector: string): Promise<ElementHandle[]>

The method runs document.querySelectorAll within the page. If no elements match the selector, the return value resolves to [].

addEventListener<K extends keyof PageEventMap>(
type: K,
listener: (event: PageEventMap[K]) => void,
options?: boolean | AddEventListenerOptions,
): void

Brings page to front (activates tab).

Get the browser the page belongs to.

Close this page in the browser

content(): Promise<string>

The full HTML contents of the page, including the DOCTYPE.

cookies(...urls: string[]): Promise<Cookie[]>

If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned.

deleteCookies(cookieDescription: DeleteCookieOptions): Promise<void>

Deletes browser cookies with matching name and url or domain/path pair.

emulateCPUThrottling(factor: number)

Enables CPU throttling to emulate slow CPUs.

evaluate<T, R extends AnyArray>(func: EvaluateFunction<T, R>, evaluateOptions?: EvaluateOptions<R>): Promise<unknown>

Runs a function in the context of the page

goto(url: string, options?: GoToOptions)

Navigate to the URL

pdf(opts?: PdfOptions): Promise<Uint8Array>

Capture screenshot of page

Reload the given page

screenshot(opts?: ScreenshotOptions): Promise<Uint8Array>

Capture screenshot of page

setContent(content: string): Promise<void>

Set page content

setCookies(cookies: Cookie[]): Promise<void>

Sets the specified cookies.

setViewportSize(size: { width: number; height: number; })

page.setViewportSize() will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport size before navigating to the page.

Returns raw celestial bindings for the page. Super unsafe unless you know what you're doing.

waitForEvent<T extends keyof PageEventMap>(event: T): Promise<PageEventMap[T]["detail"]>
waitForFunction<T, R extends AnyArray>(func: EvaluateFunction<T, R>, evaluateOptions?: EvaluateOptions<R>)

Runs a function in the context of the page until it returns a truthy value.

waitForNavigation(options?: WaitForOptions): Promise<void>

Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate.

Create a promise which resolves when network is idle

waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>

Wait for the selector to appear in page. If at the moment of calling the method the selector already exists, the method will return immediately. If the selector doesn't appear after the timeout milliseconds (10000 by default) of waiting, the function will throw.

waitForTimeout(timeout: number)

Do not use if there is an alterate way of doing your thing