Browser instructions
When using Headless Browser, you can define your own browser instructions that are executed when rendering JavaScript.
How to use it?
To use browser instructions, provide a set of browser_instructions
when creating a job.
Let’s say you want to search for the term pizza boxes
in a website.
![](https://developers.oxylabs.io/~gitbook/image?url=https%3A%2F%2F63892162-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FzrXw45naRpCZ0Ku9AjY1%252Fuploads%252FVVCJxliUYBEPcG34IThU%252Fbi_1.png%3Falt%3Dmedia%26token%3D1f689105-300d-49ce-a38a-145fd925f54f&width=768&dpr=4&quality=100&sign=a98cb45d&sv=1)
An example job parameters would look as follows:
Step 1. You must provide the "render": "html"
parameter.
Step 2. Browser instructions should be described in the "browser_instructions"
field.
The sample browser instructions above specifies that the aim is to enter a search term pizza boxes
into a search field, click search
button and wait for 5 seconds for content to load.
The scraped result should look as follows:
Scraped HTML should look like this:
![](https://developers.oxylabs.io/~gitbook/image?url=https%3A%2F%2F63892162-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FzrXw45naRpCZ0Ku9AjY1%252Fuploads%252Fskb19h4I9wV9pBJSQIP6%252Fbi_2.png%3Falt%3Dmedia%26token%3D36c0fa1e-7bb6-4bf6-8047-ab9d9bbd20dd&width=768&dpr=4&quality=100&sign=24e98ecf&sv=1)
Fetching browser resources
We provide a standalone browser instruction for fetching browser resources.
The function is defined here:
Using fetch_resource
will result in job returning the first occurrence of a Fetch/XHR resource that matches the format provided instead of the HTML that is being targeted.
Let’s say we want to target a GraphQL resource that is fetched when visiting a product page organically in the browser. We will provide job information as such:
These instructions will result in a result as such:
List of supported browser instructions
List of instructionsStatus codes
See our response codes outlined here.
Status codes in regards to instructions validation are documented here.
Errors and warnings
If there’s an error or warning resulting from your browsing actions, you’ll find it in the outcome under the keys browser_instructions_error
or browser_instructions_warnings
. For instance, if you’ve sent the following browser instructions and the expected xpath isn’t located on the page, the result will include a warning.
browser_instructions
:
Results:
Possible errors and warnings |
---|
Unexpected error happened while converting browser instructions to actions. |
Unexpected error happened while executing |
Action |
Unable to find selector type |
Last updated