Skip to main content

Preload localStorage

If you want a localStorage to be loaded before the website is visited, use preload_local_storage parameter.

tip

You can also set localStorage key/value pairs dynamically with JS Scenario.

tip

Remember to encode this parameter like in the example below.

preload_local_storage is an array of objects. Each element corresponds to single origin. The schema looks as follows:

[
{
"origin": "<origin for which the following localStorage key/values should be preloaded>"
"localStorage": [
{
"name": "<a key>",
"value": "<a value>"
},
{
"name": "<another key>",
"value": "<another value>"
}
]
},
{
"origin": "<another origin>"
"localStorage": [
{
"name": "<a key>",
"value": "<a value>"
},
{
"name": "<another key>",
"value": "<another value>"
}
]
},
]
caution

Set your origin with care. It's not necessarily the same as your url origin. Some websites redirect you to different subdomain (e.g. "https://example.com" -> "https://www.example.com"). In such a case, setting origin to https://example.com wouldn't work as actual page uses https://www.example.com.

Example

To preload localStorage with key1: value1 and key2: value2 for origin https://example.com set preload_local_storage as follows:

[
{
"origin": "https://example.com"
"localStorage": [
{
"name": "key1",
"value": "value1"
},
{
"name": "key2",
"value": "value2"
}
]
}
]

Example code can be found below.

import requests
import json

payload = {
"api_key": "[your API key]",
"url": "https://example.com",
"preload_local_storage": json.dumps(
[{"origin": "https://example.com", "localStorage": [{"name": "key1", "value": "value1"}, {"name": "key2", "value": "value2"}]}]
),
}

response = requests.get("https://scraping.narf.ai/api/v1/", params=payload)
print(response.content)