Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
goBack([options])
Returns the main resource response for the navigation, or null if the navigation is impossible (e.g., when already at the beginning of the session history).
Navigates back in the browser’s session history. This method is safer than using page.evaluate(() => window.history.back()) which can cause race conditions.
| Parameter | Type | Default | Description |
|---|---|---|---|
| options | object | null | |
| options.timeout | number | 30000 | Maximum operation time in milliseconds. Pass 0 to disable the timeout. The default value can be changed via the methods listed below. Setting the value to 0 will disable the timeout. |
| options.waitUntil | string | load | When to consider operation to have succeeded. See Events for more details. |
Methods to Change Default Values
You can change the default value using one of the following methods:
- browserContext.setDefaultNavigationTimeout(timeout)
- browserContext.setDefaultTimeout(timeout)
- page.setDefaultNavigationTimeout(timeout)
- page.setDefaultTimeout(timeout) |
Events
Caution
Avoid using
networkidlefor testing. This event might never fire on websites with high network activity. Instead, use web assertions to assess when the page is ready
You can set the event to one of the following:
'domcontentloaded': TheDOMContentLoadedevent fires.'load': Theloadevent fires.'networkidle': There are no network connections for at least 500 ms.
Returns
| Type | Description |
|---|---|
Promise<Response | null | A Promise that fulfills with the
Response> instance associated with the page, else null if navigation is not possible. |
Example
JavaScript
JavaScript
import { browser } from 'k6/browser';
import { check } from 'k6';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
// Navigate to first page
await page.goto('https://test.k6.io/browser.php');
const url1 = await page.url();
// Navigate to second page
await page.goto('https://test.k6.io/my_messages.php');
const url2 = await page.url();
// Go back to first page
const response = await page.goBack();
// Verify we're back on the first page
const currentUrl = await page.url();
check(currentUrl, {
'went back to first page': (url) => url.includes('browser.php'),
});
// Verify the response is not null (since navigation was possible)
check(response, {
'response is not null': (resp) => resp !== null,
});
// Attempt to go back again (should return null since we're at the beginning of history)
const nullResponse = await page.goBack();
check(nullResponse, {
'goBack at boundary returns null': (resp) => resp === null,
});
} finally {
await page.close();
}
}Related
- page.goForward() - Navigate forward in browser history
- page.goto() - Navigate to a specific URL
- page.reload() - Reload the current page
Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.