Browserless GraphQL API
Aside from providing the default production-sfo.browserless.io
domain for running sessions, Browserless also exposes a GraphQL API for other operations. This document goes over some critical queries, however there's more information and descriptions at the interactive GraphiQL interface located here.
The Graphql API only applies to Dedicated and Enterprise accounts.
Pressure
The pressure
query shows how much load your instance(s) are under, and whether they can accept more traffic or not. This is real-time, so if you need to check if your instance can take more traffic you can do a request to check prior to running your puppeteer.connect
call.
The pressure queries are still in BETA and may experience breaking schema changes.
# https://api.browserless.io/graphql
{
pressure(apiToken: "YOUR_API_TOKEN_HERE") {
running
recentlyRejected
queued
isAvailable
date
}
}
This request will return a JSON object with the following payload:
{
"data": {
"pressure": {
"running": 0,
"recentlyRejected": 0,
"queued": 0,
"isAvailable": true,
"date": 1524762532204
}
}
}
Metrics
The metrics
query gives you insight to how your worker(s) are performing. It details things like successful, rejected, and timed-out sessions. Eventually this will be expanded to include things like average session-time and other helpful data-points.
Below is an example of a request for metrics
and the responding payload.
The metrics queries are still in BETA and may experience breaking schema changes.
# https://api.browserless.io/graphql
{
metrics(apiToken: "YOUR_API_TOKEN_HERE") {
successful
rejected
timedout
queued
cpu
memory
date
}
}
This request returns an array of object detailing the metrics of your instance(s). If there's more than one instance stats are aggregated together in 5-minute intervals. CPU and Memory are averaged accross instances.
{
"data": {
"metrics": [
{
"successful": 0,
"rejected": 0,
"timedout": 0,
"queued": 0,
"cpu": 0.002734375,
"memory": 0.9055320561641963,
"date": 1524227700000
},
//...
]
}
}
Sessions
The sessions
query shows what browsers you have instantiated and running. This will only work for customers who have their dedicated fleet, for security purposes.
# https://api.browserless.io/graphql
{
sessions(apiToken: "YOUR_API_TOKEN_HERE") {
description
devtoolsFrontendUrl
live
kill
title
type
url
trackingId
browserId
browserWSEndpoint
browserWSEndpointClient
}
}
See More
There's a lot more you can do in the GraphQL API behind browserless, so be sure to check it out here!