Headless browser
Automating web interactions and UI testing using a headless browser

Node Description
A Headless browser - an action-type node that is required to configure interaction with a web browser using JavaScript code.
You could use AI Custom Assistant to generate code for Headless browser
🔗 Headless Browser AI Assistant
Basic Example - Get the body content of a web page
Example #2 - Wait for an HTML element before retrieving a web page's body content
Some web pages load content dynamically using JavaScript. In these cases, you need to wait for a specific selector to appear before proceeding using “await page.waitForSelector”, as shown in the example below
You could get a selector here:

Node Configuration
To configure the Headless browser node, you need to:
- Create the code in the Code window according to the requirements for interacting with the browser;
- If necessary, fill out the Proxy field block.
Proxy
The configuration block with fields:
- Enter proxy address - a field for entering the proxy address through which the request needs to be forwarded.
- Enter login - a field for entering credentials for using the proxy.
- Enter password - a field for entering credentials for using the proxy.
These fields are filled out in case access to the required website is restricted to the local network only.
Data Processing Result
The output of the Headless Browser can be a string, numerical value, JSON object, and so on. The data processing result from the Headless Browser node is accessible for configuring parameters of other nodes.
!!! tip It is recommended to wrap data in string format with quotation marks for further correct processing.
Code
Libraries
To interact with the browser using JavaScript, the Puppeteer library is used.
!!! warning In large JavaScript scripts, it may be necessary to install Puppeteer locally on your computer (installation information). To install JavaScript libraries on your computer, you need to set up NodeJS and NPM.
Inital Function run
The original function of the Headless browser node looks like this:
The "page" parameter is the result of the call to browser.newPage Puppeteer library and has the corresponding interface. All interactions with the browser page are performed using this parameter. There is no direct access to the puppeteer library or the browser from within this function.
!!! warning
Almost all operations with the page object are asynchronous. For convenience, the original run function is declared with the async keyword, allowing you to write code using async/await for better handling of asynchronous operations.
Using the function callWebhook
In the code of the Headless Browser node, there is no direct access to libraries like axios or fetch.
To make asynchronous API calls, you can use the callWebhook function. It is based on the axios library but with slightly reduced functionality.
!!! warning With this function, you can make API requests only to incoming Trigger on Webhook nodes created within the Latenode platform. Requests to other domains will result in an error.
The interface of the callWebhook(webhookUrl, options) function is similar to the interface of axios request and consists of:
webhookUrl- the URL of an incoming Trigger on Webhook within the Latenode platform;options- an object with request options.
The response will be an object with an interface similar to axios response.
Here's an example of how to use the callWebhook function:
As a result, the logs will display the object returned by the script, which was invoked via the callWebhook function for the respective Trigger on Webhook.
Examples
Google Search Query
!!! tip An example script using the Headless Browser node can be found in the Building Scenarios documentation.
Possible problems
UserAgent
Some websites may not open through a Headless Browser. In such cases, you should use the page.setUserAgent function.
Can't find XPath
A Headless Browser opens the browser using the puppeteer library, which, in turn, opens a page with a specific viewport. Websites can have responsive designs, so there may be differences in layout between a local computer and the Headless Browser. You can change the page's viewport using the page.setViewport function.