The performBrowserAction extension performs common browser-level actions from a Virtuoso journey step. It can move backward or forward in the browser history, reload the current page, replace the current URL, open a URL in a new tab, or return the current or referrer URL as a status string.
This is useful when a journey needs browser navigation behavior that is not directly represented by the standard NLP step you want to use, such as checking the current page URL, returning to the previous page, refreshing the current page, or opening a known URL in another tab.
Parameters:
-
actionrequired, a string that selects the browser action to perform. Supported values areback,forward,reload,current,replace,referrer, andblank. The aliasesprevious,next, andrefreshare also supported and map toback,forward, andreload; -
urloptional, a string URL used by actions that need a destination. It is required whenactionisreplaceorblank. Other actions ignore this input;
Note: The source code lowercases the supplied action before matching it. Pass the action as a normal string value, for example current, back, next, or blank. If the action is unknown, the extension returns an error message string rather than throwing an exception.
How to apply this to your journey
Use the extension in a journey by calling performBrowserAction with the execute command. Pass each value to the matching extension input using as action and, where needed, as url.
Note: Navigation actions such as back, forward, reload, replace, and blank are triggered by the extension, but page loading or tab switching may continue after the returned status string. Add a normal Virtuoso wait, URL assertion, page assertion, or tab-handling step after the browser action when the next step depends on the new page state.
execute "performBrowserAction" using "current" as action returning $status
assert $status contains "Current URL:"execute "performBrowserAction" using "back" as action returning $status
assert $status equals "Navigated back."You can also use the supported aliases and pass a URL for actions that need one.
execute "performBrowserAction" using "next" as action returning $status
assert $status equals "Navigated forward."
execute "performBrowserAction" using "blank" as action and "https://rocketshop.virtuoso.qa" as url returning $status
assert $status equals "Opened a new tab with given URL"You can store the action and URL in variables first, then pass those variables into the extension.
store value "replace" in $browserAction
store value "https://rocketshop.virtuoso.qa" in $targetUrl
execute "performBrowserAction" using "$browserAction" as action and "$targetUrl" as url returning $statusExample setup for reading the current URL before and after a browser action:
execute "performBrowserAction" using "current" as action returning $beforeUrl
execute "performBrowserAction" using "refresh" as action returning $refreshStatus
wait for page to load
execute "performBrowserAction" using "current" as action returning $afterUrlThe extension returns a plain-text status string. The returned value depends on the selected action.
Current URL: https://rocketshop.virtuoso.qa/
Navigated back.
Navigated forward.
Page reloaded.
URL replaced with https://rocketshop.virtuoso.qa/.
Referrer URL: https://example.com/
Opened a new tab with given URL
Error: Unknown action "open".This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension runs in the browser page context available to the Virtuoso journey step and calls native browser APIs such as window.history.back(), window.history.forward(), window.location.reload(), window.location.replace(), window.open(), window.location.href, and document.referrer. It returns a status string immediately after calling those APIs, so it does not verify that the destination page has loaded, that the browser actually moved in history, that a tab was created, or that the journey has switched to the new tab. The blank action can be affected by browser popup or user-activation restrictions, tab-handling differences, and remote-grid behavior. The referrer value can be blank because of browser privacy behavior, page policy, direct navigation, or referrer-policy configuration. Unknown actions return an error string, while a non-string or missing action can fail because the source calls action.toLowerCase(). When used in cross-browser or real-device executions, behavior can vary across Chromium, Firefox, Safari, Edge, iOS, Android, and remote grids because session history handling, reload behavior, tab creation, popup controls, PDF/file handling, and viewport or mobile restrictions are not identical. Validate this extension in each browser/device configuration used by the plan and add explicit waits or assertions after navigation actions.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 29/04/2025
Resources:
This extension does not require any external resource.
// Last updated: 29/04/2025, 06:20:39 UTC
// Define navigation functions
const navigationActions = {
back: () => {
window.history.back();
return "Navigated back.";
},
forward: () => {
window.history.forward();
return "Navigated forward.";
},
reload: () => {
window.location.reload();
return "Page reloaded.";
},
current: () => `Current URL: ${window.location.href}`,
replace: (url) => {
if (url) {
window.location.replace(url);
return `URL replaced with ${url}.`;
} else {
return "Error: URL is required to replace the current URL.";
}
},
referrer: () => `Referrer URL: ${document.referrer}`,
blank: (url) => {
if (url) {
window.open(url, '_blank');
return `Opened a new tab with given URL`;
} else {
return "Error: URL is required to open in a new tab.";
}
}
};
// Alias mappings for user-friendly commands
const aliasActions = {
previous: 'back',
next: 'forward',
refresh: 'reload'
};
// Perform browser action based on input
function performBrowserAction(action, url) {
action = action.toLowerCase();
// Resolve action alias if any
action = aliasActions[action] || action;
// Get the corresponding navigation function
const navigationAction = navigationActions[action];
// Execute the navigation function if it exists
if (navigationAction) {
return navigationAction(url);
} else {
return `Error: Unknown action "${action}".`;
}
}
return (performBrowserAction(action,url));
Comments
0 comments
Please sign in to leave a comment.