Skip to content

VM Code SDK v2 / Frame

Class: Frame ​

Represents a frame within a browser context, extending the capabilities of the Target class.

Implements ​

Extends ​

  • Target

Implements ​

  • IFrame

Properties ​

id ​

id: string

Implementation of ​

IFrame.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 ​

Selector

An instance of Selector targeting the specified element.

Implementation of ​

IFrame.$

Inherited from ​

Target.$


content() ​

content(options?): Promise<string>

Parameters ​

• options?: WaitForContentOptions

Returns ​

Promise<string>

Implementation of ​

IFrame.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


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 ​

IFrame.evaluate

Inherited from ​

Target.evaluate


fetch() ​

fetch(input, init?): Promise<Response>

Parameters ​

• input: URL | RequestInfo

• init?: RequestInit

Returns ​

Promise<Response>

Implementation of ​

IFrame.fetch

Inherited from ​

Target.fetch


getFrameBySelector() ​

getFrameBySelector(selector, options): Promise<IFrame>

Parameters ​

• selector: string | ISelector

• options: GetFrameBySelectorOptions= {}

Returns ​

Promise<IFrame>

Implementation of ​

IFrame.getFrameBySelector

Inherited from ​

Target.getFrameBySelector


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 ​

IFrame.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 ​

IFrame.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 ​

IFrame.innerText

Inherited from ​

Target.innerText


isDetached() ​

isDetached(): boolean

Determines whether the frame has been detached from the page.

Returns ​

boolean

true if the frame is detached, otherwise false.

Implementation of ​

IFrame.isDetached


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 ​

IFrame.jsonLDParser

Inherited from ​

Target.jsonLDParser


name() ​

name(): string

Retrieves the name of the frame.

Returns ​

string

The name of the frame.

Implementation of ​

IFrame.name


page() ​

page(): IPage

Retrieves the page associated with this frame.

Returns ​

IPage

An instance of the Page class representing the page containing this frame.

Implementation of ​

IFrame.page


parentFrame() ​

parentFrame(): null | IFrame

Retrieves the parent frame of this frame, if it exists.

Returns ​

null | IFrame

The parent frame, or null if there is no parent frame.

Implementation of ​

IFrame.parentFrame


parentPage() ​

parentPage(): IPage

Retrieves the parent page of the current target.

Returns ​

IPage

The parent page as an IPage instance.

Implementation of ​

IFrame.parentPage

Inherited from ​

Target.parentPage


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 ​

IFrame.readerMode

Inherited from ​

Target.readerMode


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 ​

IFrame.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 ​

IFrame.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 ​

IFrame.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 ​

IFrame.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 ​

IFrame.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 ​

IFrame.waitForURL

Inherited from ​

Target.waitForURL