Mutations
This page presents reference for all available mutations.
Back
Moves back in the browser history, optionally accepting parameters for waitUntil
and timeout
. Returns null
if no back navigation is possible.
- Schema
- Example
back(
waitUntil: WaitUntilHistory = commit
timeout: Float
): HTTPResponse
mutation GoBack {
firstNav: goto(url: "https://example.com") {
time
}
secondNav: goto(url: "https://browserless.com") {
time
}
back(waitUntil: domContentLoaded) {
status
}
}
Argument | Type | Description |
---|---|---|
waitUntil | WaitUntilHistory | When to consider the page fully loaded and proceed with further execution. Defaults to commit . |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the page to load, overriding any defaults. |
Response: HTTPResponse
Checkbox
Checks or unchecks a checkbox input element.
- Schema
- Example
checkbox(
selector: String!
checked: Boolean!
wait: Boolean = true
scroll: Boolean = true
visible: Boolean = false
timeout: Float
): ClickResponse
mutation ClickCheckbox {
goto(url: "https://example.com") {
status
}
checkbox(
checked: true
selector: "input[type='checkbox']"
) {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String! | The CSS selector of the checkbox element to check/uncheck. |
checked | Boolean! | Whether the checkbox input should be checked or unchecked. |
wait | Boolean = true | Whether to wait for the checkbox element to be present in the DOM. |
scroll | Boolean = true | Whether to scroll to the checkbox element before clicking. Defaults to true . |
visible | Boolean = false | Whether to check/uncheck the checkbox only if it is visible. |
timeout | Float | How long to wait for the element to appear before timing out, overriding any defaults. |
Response: ClickResponse
Click
Waits for the element to be visible, scrolls to it if needed, and clicks on it using native events.
- Schema
- Example
click(
selector: String!
wait: Boolean = true
scroll: Boolean = true
visible: Boolean = false
timeout: Float
): ClickResponse
mutation ClickButton {
goto(url: "https://example.com") {
status
}
click(selector: "a") {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String! | A query-selector compatible string, JavaScript that returns an HTML Node, or a Browserless-deep query. Examples include: - A simple <button /> element: "button" .- A JavaScript snippet returning a button element: "document.querySelector('button')" - A Browserless deep query, starting with < for traversing iframes, shadow DOMs, etc.: "< button" |
wait | Boolean = true | Whether to wait for the element to be present in the DOM. |
scroll | Boolean = true | Whether to scroll to the element before clicking. Defaults to true. |
visible | Boolean = false | Whether to click the element only if it's visible. |
timeout | Float | How long to wait for the element to appear before timing out, overriding defaults. |
Response: ClickResponse
Content
Sets the given HTML content on the page with an optional waitUntil
parameter.
- Schema
- Example
content(
html: String!
waitUntil: WaitUntilHistory
): HTTPResponse
mutation SetContent {
content(html: "<h1>Hello, World!</h1>") {
status
}
}
Argument | Type | Description |
---|---|---|
html | String! | Sets the content of the page to the provided HTML value, then returns the page's content. |
waitUntil | WaitUntilHistory | When to consider the page fully loaded and proceed with further execution. |
Response: HTTPResponse
Cookies
Sets and gets cookies on the page.
- Schema
- Example
cookies(
cookies: [CookieInput]
): CookieResponse
mutation SetCookies {
# Get the cookies on the page
getCookies: cookies {
cookies {
name
value
}
}
# Set a cookie on the page
setCookies: cookies(cookies: [
{
name: "my-cookie"
value: "my-value"
url: "https://example.com"
}
]) {
cookies {
name
value
}
}
}
Argument | Type | Description |
---|---|---|
cookies | [CookieInput] | The cookies to set on the page. |
Response: CookieResponse
Evaluate
Evaluates JavaScript in the browser's page environment, using either raw content or a URL pointing to the script.
- Schema
- Example
evaluate(
content: String
url: String
timeout: Float
): EvaluateResponse
mutation EvaluateScript {
byContent: evaluate(content: "2 + 2") {
value
}
byUrl: evaluate(url: "https://example.com/script.js") {
value
}
}
Argument | Type | Description |
---|---|---|
content | String | The raw JavaScript code to evaluate. Wrapped in an async function, allowing return , await , and other async concepts. Returns any stringified value. |
url | String | The URL of the JavaScript script to evaluate. Wrapped in an async function, allowing return , await , and other async concepts. Returns any stringified value. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the script to finish evaluating, overriding defaults. Useful for longer-running async scripts. |
Response: EvaluateResponse
Forward
Moves forward in the browser history, optionally accepting parameters for waitUntil
and timeout
. Returns null
if no forward navigation is possible.
- Schema
- Example
forward(
waitUntil: WaitUntilHistory = commit
timeout: Float
): HTTPResponse
mutation GoForward {
firstNav: goto(url: "https://example.com", waitUntil: load) {
time
}
secondNav: goto(url: "https://browserless.io", waitUntil: load) {
time
}
back(waitUntil: domContentLoaded) {
status
}
forward(waitUntil: domContentLoaded) {
status
}
}
Argument | Type | Description |
---|---|---|
waitUntil | WaitUntilHistory | When to consider the page fully loaded and proceed with further execution. Defaults to commit . |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the page to load, overriding any defaults. |
Response: HTTPResponse
Goto
Navigates to a URL with optional parameters for waitUntil
and timeout
.
- Schema
- Example
goto(
url: String!
waitUntil: WaitUntilGoto = commit
timeout: Float
): HTTPResponse
mutation Goto {
goto(url: "https://example.com") {
status
}
}
Argument | Type | Description |
---|---|---|
url | String! | The fully-qualified URL of the page you'd like to navigate to. |
waitUntil | WaitUntilGoto | When to consider the page fully loaded and proceed with further execution. Defaults to commit . |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the page to load, overriding any defaults. |
Response: HTTPResponse
HTML
Returns the HTML content of the page or a specified selector.
- Schema
- Example
html(
selector: String
visible: Boolean = false
timeout: Float
): HTMLResponse
mutation GetHTML {
goto(url: "https://example.com") {
status
}
html(selector: "h1") {
html
}
}
Argument | Type | Description |
---|---|---|
selector | String | The DOM selector of the element whose HTML content you want to retrieve. |
visible | Boolean = false | Whether to return the HTML content of the element only if it's visible. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the selector to appear, overriding defaults. |
Response: HTMLResponse
Hover
Waits for the element to be visible, scrolls to it if needed, and hovers over it using native events.
- Schema
- Example
hover(
selector: String
x: Float
y: Float
wait: Boolean = true
scroll: Boolean = true
visible: Boolean = false
timeout: Float
): HoverResponse
mutation HoverElement {
goto(url: "https://example.com") {
status
}
hover(selector: "a") {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String | The CSS selector of the element on the page you want to hover on. |
x | Float | The x-coordinate, in pixels, to hover on the page. |
y | Float | The y-coordinate, in pixels, to hover on the page. |
wait | Boolean = true | Whether to wait for the element to be present in the DOM. |
scroll | Boolean = true | Whether to scroll to the element before hovering. Defaults to true. |
visible | Boolean = false | Whether to hover on the element only if it's visible. |
timeout | Float | How long to wait for the element to appear before timing out, overriding any defaults. |
Response: HoverResponse
If
Triggers a nested branch of work when a given condition is true. This method performs a point-in-time check and does not wait for the conditions to be met. Use the wait
method for awaiting specific behaviors.
- Schema
- Example
if(
selector: String
visible: Boolean = false
request: RequestInput
response: ResponseInput
): Mutation
mutation If {
goto(url: "https://example.com") {
status
}
# Will only trigger the screenshot if the h1 is present
if(selector: "h1") {
screenshot {
base64
}
}
}
Argument | Type | Description |
---|---|---|
selector | String | Triggers the subsequent conditions if the selector is immediately present. |
visible | Boolean = false | Determines whether to consider the selector visible within the viewport when evaluating conditions. |
request | RequestInput | Triggers the nested conditions if a request has been made with the specified conditions. |
response | ResponseInput | Triggers the nested conditions if a response has been received with the specified conditions. |
IfNot
Triggers a nested branch of work when a given condition is false. This method performs a point-in-time check and does not wait for the conditions to be met. Use the wait
method for awaiting specific behaviors.
- Schema
- Example
ifnot(
selector: String
request: RequestInput
response: ResponseInput
): Mutation
mutation IfNot {
goto(url: "https://example.com") {
status
}
# Will only trigger the screenshot if the h2 is not present
ifnot(selector: "h2") {
screenshot {
base64
}
}
}
Argument | Type | Description |
---|---|---|
selector | String | Triggers the subsequent conditions if the selector is immediately present. |
request | RequestInput | Triggers the nested conditions if a request has been made with the specified conditions. |
response | ResponseInput | Triggers the nested conditions if a response has been received with the specified conditions. |
JavaScriptEnabled
Sets and gets JavaScript execution on the page.
- Schema
- Example
javaScriptEnabled(
enabled: Boolean
): JavaScriptResponse
mutation JavaScript {
status: javaScriptEnabled {
enabled
}
disable: javaScriptEnabled(enabled: false) {
enabled
}
enable: javaScriptEnabled(enabled: true) {
enabled
}
}
Argument | Type | Description |
---|---|---|
enabled | Boolean | Whether or not to enable JavaScript on the page. |
Response: JavaScriptResponse
PDF
Generates a PDF of the page with customizable formatting and layout options.
- Schema
- Example
pdf(
format: PDFPageFormat
landscape: Boolean
displayHeaderFooter: Boolean
printBackground: Boolean
scale: Float
width: FloatOrString
height: FloatOrString
marginTop: FloatOrString
marginBottom: FloatOrString
marginLeft: FloatOrString
marginRight: FloatOrString
pageRanges: String
headerTemplate: String
footerTemplate: String
preferCSSPageSize: Boolean
transferMode: String
generateTaggedPDF: Boolean
generateDocumentOutline: Boolean
): PDFResponse
mutation PDF {
goto(url: "https://example.com", waitUntil: firstMeaningfulPaint) {
status
}
simple: pdf {
base64
}
customArgs: pdf(
format: a5
displayHeaderFooter: true
headerTemplate: "<span style=\"font-size: 16pt;\">Hello World</span>"
) {
base64
}
}
Argument | Type | Description |
---|---|---|
format | PDFPageFormat | The page format to use for the PDF. |
landscape | Boolean | Paper orientation. Defaults to false . |
displayHeaderFooter | Boolean | Display header and footer. Defaults to false . |
printBackground | Boolean | Print background graphics. Defaults to false . |
scale | Float | Scale of the webpage rendering. Defaults to 1 . |
width | FloatOrString | Width in inches or CSS unit. Defaults to 8.5 inches . |
height | FloatOrString | Height in inches or CSS unit. Defaults to 11 inches . |
marginTop | FloatOrString | Top margin in inches or CSS unit. Defaults to 1cm (~0.4 inches) . |
marginBottom | FloatOrString | Bottom margin in inches or CSS unit. Defaults to 1cm (~0.4 inches) . |
marginLeft | FloatOrString | Left margin in inches or CSS unit. Defaults to 1cm (~0.4 inches) . |
marginRight | FloatOrString | Right margin in inches or CSS unit. Defaults to 1cm (~0.4 inches) . |
pageRanges | String | Paper ranges to print, e.g., '1-5, 8, 11-13' . Defaults to an empty string (entire document). |
headerTemplate | String | HTML template for the print header. Supports specific classes for printing values. |
footerTemplate | String | HTML template for the print footer. Supports specific classes for printing values. |
preferCSSPageSize | Boolean | Whether to prefer page size defined by CSS. Defaults to false . |
transferMode | String | Return as stream (PrintToPDFRequestTransferMode enum). |
generateTaggedPDF | Boolean | Whether to generate tagged (accessible) PDF. Defaults to embedder choice. |
generateDocumentOutline | Boolean | Whether to embed the document outline into the PDF. |
Response: PDFResponse
Preferences
Sets configuration for the entirety of the session, replacing defaults like the 30-second timeout default.
- Schema
- Example
preferences(timeout: Float): DefaultResponse
mutation Preferences {
preferences(timeout: 10000) {
timeout
}
}
Argument | Type | Description |
---|---|---|
timeout | Float | Sets a default timeout for all methods, including goto , type , wait , etc. |
Response: DefaultResponse
QuerySelector
Passes through certain properties of the browser's native querySelector
API.
- Schema
- Example
querySelector(
selector: String!
timeout: Float
visible: Boolean = false
): QuerySelectorResponse
mutation QuerySelector {
goto(url: "https://example.com") {
status
}
query: querySelector(selector: "h1") {
innerHTML
}
}
Argument | Type | Description |
---|---|---|
selector | String! | The CSS selector to query for in the DOM. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the selector to appear, overriding defaults. |
visible | Boolean = false | Whether to query only elements that are visible. |
Response: QuerySelectorResponse
QuerySelectorAll
Passes through certain properties of the browser's native querySelectorAll
API.
- Schema
- Example
querySelectorAll(
selector: String!
timeout: Float
visible: Boolean = false
): [QuerySelectorResponse]
mutation QuerySelectorAll {
goto(url: "https://example.com") {
status
}
query: querySelectorAll(selector: "h1") {
innerHTML
}
}
Argument | Type | Description |
---|---|---|
selector | String! | The CSS selector to query for in the DOM. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the selector to appear, overriding defaults. |
visible | Boolean = false | Whether to query only elements that are visible. |
Response: [QuerySelectorResponse]
Reconnect
Returns a payload with reconnection information to reconnect back to the same browser session.
- Schema
- Example
reconnect(
timeout: Float = 30000
): ReconnectionResponse
mutation Reconnect {
goto(url: "https://example.com") {
status
}
reconnect(timeout: 30000) {
browserQLEndpoint
browserWSEndpoint
devtoolsFrontendUrl
webSocketDebuggerUrl
}
}
Argument | Type | Description |
---|---|---|
timeout | Float = 30000 | The amount of time, in milliseconds, to leave the browser open without a connection before it is manually terminated. Defaults to 30 seconds. |
Response: ReconnectionResponse
Reload
Reloads the given page with optional parameters for waitUntil
and timeout
.
- Schema
- Example
reload(
waitUntil: WaitUntilHistory = commit
timeout: Float
): HTTPResponse
mutation Reload {
goto(url: "https://example.com") {
status
}
reload(timeout: 10000) {
status
}
}
Argument | Type | Description |
---|---|---|
waitUntil | WaitUntilHistory | When to consider the page fully loaded and proceed with further execution. Defaults to commit . |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the page to load, overriding any defaults. |
Response: HTTPResponse
Screenshot
Takes a screenshot of the page or a specific selector.
- Schema
- Example
screenshot(
selector: String
captureBeyondViewport: Boolean
clip: ScreenshotClip
fromSurface: Boolean
fullPage: Boolean
omitBackground: Boolean
optimizeForSpeed: Boolean
quality: Float
type: ScreenshotType
): ScreenshotResponse
mutation Screenshot {
goto(url: "https://example.com") {
status
}
screenshot {
base64
}
}
Argument | Type | Description |
---|---|---|
selector | String | The CSS selector of the element on the page to screenshot. |
captureBeyondViewport | Boolean | Captures the screenshot beyond the viewport. Defaults to False unless clip is specified. |
clip | ScreenshotClip | Specifies the region of the page or element to clip for the screenshot. |
fromSurface | Boolean | Captures the screenshot from the surface, rather than the view. Defaults to True . |
fullPage | Boolean | Captures a screenshot of the full page. Defaults to False . |
omitBackground | Boolean | Hides the default white background for transparent screenshots. Defaults to False . |
optimizeForSpeed | Boolean | Optimizes image encoding for speed instead of resulting size. Defaults to False . |
quality | Float | Specifies image quality, between 0-100. Not applicable for PNG images. |
type | ScreenshotType | The final format of the screenshot. |
Response: ScreenshotResponse
Scroll
Waits for a selector and then scrolls to it on the page or to a specified x, y coordinate in pixels.
- Schema
- Example
scroll(
selector: String
x: Float
y: Float
wait: Boolean = true
visible: Boolean = false
timeout: Float
): ScrollResponse
mutation Scroll {
goto(url: "https://example.com") {
status
}
scroll(selector: "h1") {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String | The DOM selector of the element on the page to scroll to. |
x | Float | The x-coordinate, in pixels, to scroll to. |
y | Float | The y-coordinate, in pixels, to scroll to. |
wait | Boolean = true | Whether to wait for the element before scrolling to it. |
visible | Boolean = false | Whether to scroll to the element only if it's visible. |
timeout | Float | How long to wait for the element to appear before timing out, overriding defaults. |
Response: ScrollResponse
Select
Selects a value from a dropdown or multiple select element.
- Schema
- Example
select(
selector: String!
value: StringOrArray!
wait: Boolean = true
scroll: Boolean = true
visible: Boolean = false
timeout: Float
): SelectResponse
mutation Select {
goto(url: "https://example.com") {
status
}
single: select(
selector: "select"
value: "option1"
) {
time
}
multi: select(
selector: "select"
value: ["option1", "option2"]
) {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String! | The CSS selector of the element to select a value from. |
value | StringOrArray! | The value or values to select from the dropdown or multiple select element. |
wait | Boolean = true | Whether to wait for the select element to be present in the DOM. |
scroll | Boolean = true | Whether to scroll to the select element before selecting a value. Defaults to true . |
visible | Boolean = false | Whether to select a value only if the element is visible. |
timeout | Float | How long to wait for the element to appear before timing out, overriding any defaults. |
Response: SelectResponse
Solve
🚨 EXPERIMENTAL 🚨
Solves a captcha or other challenge, specified by the "type" of captcha to solve.
- Schema
- Example
solve(
type: CaptchaTypes!
wait: Boolean = true
timeout: Float
): CaptchaResponse
mutation SolveCaptcha {
goto(url: "https://protected.domain") {
status
}
solve(type: hcaptcha) {
found
solved
time
}
}
Argument | Type | Description |
---|---|---|
type | CaptchaTypes! | An enum specifying the type of captcha to look for and solve. |
wait | Boolean = true | Whether to wait for the captcha to be present on the page. |
timeout | Float | The time, in milliseconds, to wait for a captcha to appear. Only valid when wait = true . |
Response: CaptchaResponse
Text
Returns the text content of the page or a specified selector.
- Schema
- Example
text(
selector: String
visible: Boolean = false
timeout: Float
): TextResponse
mutation GetText {
goto(url: "https://example.com") {
status
}
selector: text(selector: "h1") {
text
}
fullPage: text {
text
}
}
Argument | Type | Description |
---|---|---|
selector | String | The DOM selector of the element whose text content you want to retrieve. |
visible | Boolean = false | Whether to return the text content of the element only if it's visible. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the selector to appear, overriding defaults. |
Response: TextResponse
Title
Returns the title of the page that the browser is currently at.
- Schema
- Example
title: TitleResponse
mutation GetTitle {
goto(url: "https://example.com") {
status
}
title {
title
}
}
Response: TitleResponse
Type
Types text into an element by scrolling to it, clicking it, and emitting key events for each character.
- Schema
- Example
type(
text: String!
selector: String!
delay: [Int] = [50, 200]
wait: Boolean = true
scroll: Boolean = true
visible: Boolean = false
interactable: Boolean = true
timeout: Float
): TypeResponse
mutation Type {
goto(url: "https://example.com") {
status
}
type(
text: "Hello, World!"
selector: "input[type='text']"
) {
time
}
}
Argument | Type | Description |
---|---|---|
text | String! | The text content to type into the element. |
selector | String! | The CSS selector of the element where the text will be typed. |
delay | [Int] = [50, 200] | The delay between keystrokes, in milliseconds. Values are used as a range and chosen at random. |
wait | Boolean = true | Whether to wait for the element to be present in the DOM. |
scroll | Boolean = true | Whether to scroll to the element before typing. Defaults to true. |
visible | Boolean = false | Whether to type into the element only if it's visible. |
interactable | Boolean = true | Whether to check if the element is interactable by hovering over it and confirming its availability. |
timeout | Float | How long to wait for the element to appear before timing out, overriding defaults. |
Response: TypeResponse
URL
Returns the URL of the page that the browser is currently at.
- Schema
- Example
url: URLResponse
mutation GetURL {
goto(url: "https://example.com") {
status
}
url {
url
}
}
Response: URLResponse
Verify
🚨 EXPERIMENTAL 🚨
Clicks a verification button to assert human-like interaction.
- Schema
- Example
verify(
type: VerifyTypes!
wait: Boolean = true
timeout: Float
): CaptchaResponse
mutation Verify {
goto(url: "https://protected.domain") {
status
}
verify(type: cloudflare) {
found
solved
time
}
}
Argument | Type | Description |
---|---|---|
type | VerifyTypes! | An enum specifying the type of verification to look for and interact with. |
wait | Boolean = true | Whether to wait for the verification to be present on the page. |
timeout | Float | The time, in milliseconds, to wait for a verification to appear. Only valid when wait = true . |
Response: CaptchaResponse
WaitForNavigation
Waits for a navigation event to occur, typically used when clicking an element and waiting for a page load.
- Schema
- Example
waitForNavigation(
waitUntil: WaitUntilGoto = commit
timeout: Float
): HTTPResponse
mutation WaitForNavigation {
goto(url: "https://example.com") {
status
}
waitForNavigation(waitUntil: load) {
status
}
}
Argument | Type | Description |
---|---|---|
waitUntil | WaitUntilGoto | When to consider the page fully loaded and proceed with further execution. Defaults to commit . |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the page to load, overriding any defaults. |
Response: HTTPResponse
WaitForRequest
Waits for the browser to make a particular request.
- Schema
- Example
waitForRequest(
url: String
method: Method
timeout: Float
): WaitForRequest
mutation WaitForRequest {
goto(url: "https://browserless.io") {
status
}
waitForRequest(method: GET) {
time
}
}
Argument | Type | Description |
---|---|---|
url | String | The pattern of the request URL to wait for, using glob-style pattern-matching. |
method | Method | The HTTP method of the request to wait for. |
timeout | Float | How long to wait for the request to be made before timing out, overriding any defaults. |
Response: WaitForRequest
WaitForResponse
Waits for a specific network response to be made back to the browser.
- Schema
- Example
waitForResponse(
url: String
codes: [Int]
): WaitForResponse
mutation WaitForResponse {
goto(url: "https://browserless.io") {
status
}
waitForResponse(codes: [200]) {
time
}
}
Argument | Type | Description |
---|---|---|
url | String | The pattern of the response URL to wait for, using glob-style pattern-matching. |
codes | [Int] | The HTTP response code(s) to wait for. Can be a single HTTP code or a list of desired codes. |
Response: WaitForResponse
WaitForSelector
Waits for a given selector to be present in the DOM, with an optional visibility check.
- Schema
- Example
waitForSelector(
selector: String!
visible: Boolean = false
timeout: Float
): WaitForSelector
mutation WaitForSelector {
goto(url: "https://example.com") {
status
}
waitForSelector(selector: "h1") {
time
}
}
Argument | Type | Description |
---|---|---|
selector | String! | The selector to wait for until it is present in the DOM. |
visible | Boolean = false | Whether to consider the element as present only if it's visible. |
timeout | Float | The maximum amount of time, in milliseconds, to wait for the selector to appear, overriding defaults. |
Response: WaitForSelector
WaitForTimeout
Waits for a specific period of time, defined in milliseconds.
- Schema
- Example
waitForTimeout(
time: Float!
): WaitForTimeout
mutation WaitForTimeout {
waitForTimeout(time: 1000) {
time
}
}
Argument | Type | Description |
---|---|---|
time | Float! | The amount of time to wait for, in milliseconds. |
Response: WaitForTimeout