Preload localStorage

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

preload_local_storage syntax

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>"
      }
    ]
  },
]

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:

GET
/api/v1/
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)