Appearance
VM Code SDK v2 / Page
Class: Page
Extends
Target
Implements
IPage
Properties
id
id:
string
Implementation of
IPage.id
Inherited from
Target.id
Methods
$()
$(
s,options):Selector
Creates a selector instance targeting a specific element by CSS selector.
Parameters
• s: string
The CSS selector string.
• options: SelectorOptions
Additional options for the selector.
Returns
An instance of Selector targeting the specified element.
Implementation of
IPage.$
Inherited from
Target.$
clearCookies()
clearCookies():
Promise<void>
Clears all cookies from the current browser context.
Returns
Promise<void>
A promise that resolves when all cookies have been cleared.
Implementation of
IPage.clearCookies
close()
close():
Promise<void>
Returns
Promise<void>
Implementation of
IPage.close
content()
content(
options?):Promise<string>
Parameters
• options?: WaitForContentOptions
Returns
Promise<string>
Implementation of
IPage.content
Inherited from
Target.content
cookieConsent()
cookieConsent(
buttonText):Promise<void>
Handles cookie consent dialogs by clicking the specified button.
Parameters
• buttonText: string
The text of the button to click for cookie consent.
Returns
Promise<void>
Inherited from
Target.cookieConsent
cookies()
cookies(
urls?):Promise<Cookie[]>
Retrieves cookies from the current or specified URLs.
Parameters
• urls?: string | string[]
The URLs to retrieve cookies from. If omitted, cookies from all URLs are returned.
Returns
Promise<Cookie[]>
A promise that resolves to an array of cookies.
Implementation of
IPage.cookies
evaluate()
evaluate<
Arg,R>(jsCode,arg):Promise<R>
Evaluates JavaScript code or a function on the page.
Type parameters
• Arg
• R
Parameters
• jsCode: string | (arg) => R | Promise<R>
The JavaScript code or function to evaluate.
• arg: Arg
The argument to pass to the function.
Returns
Promise<R>
A promise that resolves to the result of the evaluation.
Implementation of
IPage.evaluate
Inherited from
Target.evaluate
fetch()
fetch(
input,init?):Promise<Response>
Parameters
• input: URL | RequestInfo
• init?: RequestInit
Returns
Promise<Response>
Implementation of
IPage.fetch
Inherited from
Target.fetch
getFrameBySelector()
getFrameBySelector(
selector,options):Promise<IFrame>
Parameters
• selector: string | ISelector
• options: GetFrameBySelectorOptions= {}
Returns
Promise<IFrame>
Implementation of
IPage.getFrameBySelector
Inherited from
Target.getFrameBySelector
getKeyboard()
getKeyboard():
Keyboard
Retrieves the Keyboard object associated with the page. This allows for simulation of keyboard input, enabling typing or key press simulations.
Returns
Keyboard
The Keyboard object for the current page.
Implementation of
IPage.getKeyboard
getMouse()
getMouse():
Mouse
Retrieves the Mouse object associated with the page. This allows for simulation of mouse events such as click, double-click, hover, etc.
Returns
Mouse
The Mouse object for the current page.
Implementation of
IPage.getMouse
getTouchscreen()
getTouchscreen():
Touchscreen
Retrieves the Touchscreen object associated with the page. This allows for simulation of touch events such as tap, swipe, etc.
Returns
Touchscreen
The Touchscreen object for the current page.
Implementation of
IPage.getTouchscreen
goto()
goto(
url,options?):Promise<null|Response>
Navigates the main frame to a specified URL and returns the main resource response. If there are multiple redirects, the navigation will resolve with the first non-redirect response.
Parameters
• url: string
The URL to navigate the page to. This URL should include the scheme, e.g., https://. If a baseURL is provided via the context options and the passed URL is a path, it is resolved using the new URL() constructor.
• options?: object & WaitUntilOption
Navigation options, including timeout settings and other navigation parameters.
Returns
Promise<null | Response>
Implementation of
IPage.goto
Inherited from
Target.goto
Remarks
This method will throw an error under the following conditions:
- There is an SSL error (e.g., in case of self-signed certificates).
- The target URL is invalid.
- The navigation timeout is exceeded.
- The remote server does not respond or is unreachable.
- The main resource fails to load.
However, this method will not throw an error for any valid HTTP status code returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error".
Note
The method either throws an error or returns a main resource response. Exceptions include navigation to about:blank or navigation to the same URL with a different hash, which would succeed and return null.
Note
Headless mode does not support navigation to a PDF document.
This function serves as a shortcut for navigating the main frame to a specified URL.
innerHTML()
innerHTML(
options):Promise<string>
Retrieves the inner HTML content of the root HTML element.
Parameters
• options: TimeoutOption
Configuration options including a timeout setting.
Returns
Promise<string>
A promise that resolves to the inner HTML content as a string.
Implementation of
IPage.innerHTML
Inherited from
Target.innerHTML
innerText()
innerText(
options):Promise<string>
Retrieves the inner text content of the body element.
Parameters
• options: TimeoutOption
Configuration options including a timeout setting.
Returns
Promise<string>
A promise that resolves to the inner text content as a string.
Implementation of
IPage.innerText
Inherited from
Target.innerText
isClosed()
isClosed():
boolean
Returns
boolean
Implementation of
IPage.isClosed
jsonLDParser()
jsonLDParser(
types,options):Promise<JSONObject>
Parses JSON-LD data from a script tag of type 'application/ld+json' on the current page. It filters the JSON-LD data based on the specified types.
Parameters
• types: string | string[]
A string or array of strings representing the types of JSON-LD data to parse.
• options: TimeoutOption
Configuration options including a timeout setting.
Returns
Promise<JSONObject>
The first JSON-LD object that matches the specified types, or an empty object if none match.
Implementation of
IPage.jsonLDParser
Inherited from
Target.jsonLDParser
parentPage()
parentPage():
IPage
Retrieves the parent page of the current target.
Returns
IPage
The parent page as an IPage instance.
Implementation of
IPage.parentPage
Inherited from
Target.parentPage
pdf()
pdf(
options):Promise<Buffer>
Generates a PDF of the current page. This method can alter the media type of the page before generating the PDF if specified in the options.
Parameters
• options: PagePdfOptions
{PagePdfOptions} Configuration options for generating the PDF, such as media type, page format, and file name.
Returns
Promise<Buffer>
A promise that resolves with the PDF data.
Implementation of
IPage.pdf
readerMode()
readerMode(
options?):Promise<null|Readability<string>>
Initiates reader mode with a default of 5 retries.
Parameters
• options?: WaitForContentOptions
Optional. Configuration options for waiting for page content.
Returns
Promise<null | Readability<string>>
A Readability object if successful, or null if it fails to enable reader mode after retries.
Implementation of
IPage.readerMode
Inherited from
Target.readerMode
route()
route(
url,handler,options?):Promise<void>
Defines a route to intercept and handle network requests.
Parameters
• url: string | RegExp | (url) => boolean
The URL pattern to intercept. This can be a string, RegExp, or a function that returns a boolean.
• handler
The function to execute when a request matching the URL pattern is intercepted. It receives the route and request as parameters.
• options?
Optional. Configuration options for the route, such as the number of times to intercept (times).
• options.times?: number
Returns
Promise<void>
A promise that resolves when the route is set.
Implementation of
IPage.route
screenshot()
screenshot(
options):Promise<Buffer>
Takes a screenshot of the current page. By default, it captures the full page unless specified otherwise in the options.
Parameters
• options: PageScreenshotOptions
{PageScreenshotOptions} Options for screenshot configuration such as fullPage and filename.
Returns
Promise<Buffer>
A promise that resolves to the screenshot buffer.
Implementation of
IPage.screenshot
setGeolocation()
setGeolocation(
latitude,longitude,accuracy):Promise<void>
Sets the geolocation for the current browser context.
Parameters
• latitude: number
The latitude of the geolocation.
• longitude: number
The longitude of the geolocation.
• accuracy: number= 0
The accuracy of the geolocation in meters, defaults to 0.
Returns
Promise<void>
A promise that resolves when the geolocation is set.
Implementation of
IPage.setGeolocation
tryReaderMode()
tryReaderMode(
options?,retryCnt?):any
Attempts to enable reader mode by parsing the page content into a more readable format. This function recursively tries to parse the content up to a specified number of retries.
Parameters
• options?: WaitForContentOptions
Optional. Configuration options for waiting for page content.
• retryCnt?: number= 5
Optional. The number of retries for attempting reader mode. Defaults to 5.
Returns
any
A Readability object if successful, or null if all retries fail.
Inherited from
Target.tryReaderMode
url()
url():
string
Retrieves the current URL of the target.
Returns
string
The URL as a string.
Implementation of
IPage.url
Inherited from
Target.url
waitForFunction()
waitForFunction<
Arg,R>(jsCode,arg,options):Promise<void>
Waits for a JavaScript function to return true.
Type parameters
• Arg
• R
Parameters
• jsCode: string | (arg) => R | Promise<R>
The JavaScript code or function to evaluate.
• arg: Arg
The argument to pass to the function.
• options
Options including timeout and polling interval.
• options.polling?: number | "raf"
• options.timeout?: number
Returns
Promise<void>
A promise that resolves when the function returns true.
Implementation of
IPage.waitForFunction
Inherited from
Target.waitForFunction
waitForLoadState()
waitForLoadState(
state?,options?):Promise<void>
Waits for the page to reach a specific load state.
Parameters
• state?: "load" | "domcontentloaded" | "networkidle"
The load state to wait for: "load", "domcontentloaded", or "networkidle".
• options?= {}
Configuration options including a timeout setting.
• options.timeout?: number
Returns
Promise<void>
A promise that resolves when the specified load state is reached.
Implementation of
IPage.waitForLoadState
Inherited from
Target.waitForLoadState
waitForSelector()
waitForSelector(
selector,options):Promise<Selector>
Waits for a selector to appear in the page and be in a specific state.
Parameters
• selector: string | ISelector
The selector or ISelector instance to wait for.
• options: WaitForSelectorOptions
Options including timeout and state for waiting for the selector.
Returns
Promise<Selector>
A promise that resolves to the Selector instance when the element is in the desired state.
Implementation of
IPage.waitForSelector
Inherited from
Target.waitForSelector
waitForTimeout()
waitForTimeout(
n):Promise<void>
Waits for a specified amount of time.
Parameters
• n: number
The number of milliseconds to wait.
Returns
Promise<void>
Implementation of
IPage.waitForTimeout
Inherited from
Target.waitForTimeout
waitForURL()
waitForURL(
url,options):Promise<void>
Waits for the URL of the page to change to a specified URL.
Parameters
• url: string
The URL to wait for.
• options: WaitForUrlOptions
Options for waiting for the URL.
Returns
Promise<void>
A promise that resolves when the URL changes to the specified URL.
Implementation of
IPage.waitForURL
Inherited from
Target.waitForURL