Go to an URL. This is similar to entering an URL in a browser
address bar, pressing Enter and waiting until page loads.

Signature:ok,reason=splash.go{url,baseurl=nil}

Parameters:

url - URL to load;

baseurl - base URL to use, optional. When baseurl argument is passed
the page is still loaded from url, but it is rendered as if it was
loaded from baseurl: relative resource paths will be relative
to baseurl, and the browser will think baseurl is in address bar.

Returns:ok,reason pair. If ok is nil then error happened during
page load; reason provides an information about error type.

Two types of errors are reported (ok can be nil in two cases):

There is nothing to render. This can happen if a host doesn’t exist,
server dropped connection, etc. In this case reason is "error".

Server returned a response with 4xx or 5xx HTTP status code.
reason is "http<code>" in this case, i.e. for
HTTP 404 Not Found reason is "http404".

Error handling example:

localok,reason=splash:go("http://example.com")ifnotok:ifreason:sub(0,4)=='http'then-- handle HTTP errorselse-- handle other errorsendend-- process the page-- assert can be used as a shortcut for error handlingassert(splash:go("http://example.com"))

Errors (ok==nil) are only reported when “main” webpage request failed.
If a request to a related resource failed then no error is reported by
splash:go. To detect and handle such errors (e.g. broken image/js/css
links, ajax requests failed to load) use splash:har.

splash:go follows all HTTP redirects before returning the result,
but it doesn’t follow HTML <metahttp-equiv="refresh"...> redirects or
redirects initiated by JavaScript code. To give the webpage time to follow
those redirects use splash:wait.

cancel_on_redirect - if true (not a default) and a redirect
happened while waiting, then splash:wait stops earlier and returns
nil,"redirect". Redirect could be initiated by
<metahttp-equiv="refresh"...> HTML tags or by JavaScript code.

cancel_on_error - if true (default) and an error which prevents page
from being rendered happened while waiting (e.g. an internal WebKit error
or a network error like a redirect to a non-resolvable host)
then splash:wait stops earlier and returns nil,"error".

Returns:ok,reason pair. If ok is nil then the timer was
stopped prematurely, and reason contains a string with a reason.
Possible reasons are "error" and "redirect".

By default wait timer continues to tick when redirect happens.
cancel_on_redirect option can be used to restart the timer after
each redirect. For example, here is a function that waits for a given
time after each page load in case of redirects:

Lua strings, numbers, booleans and tables can be passed as arguments;
they are converted to JS strings/numbers/booleans/objects.
Currently it is not possible to pass other Lua objects. For example, it
is not possible to pass a wrapped JavaScript function or a regular Lua function
as an argument to another wrapped JavaScript function.

Lua → JavaScript conversion rules:

Lua

JavaScript

string

string

number

number

boolean

boolean

table

Object

nil

undefined

Function result is converted from JavaScript to Lua data type. Only simple
JS objects are supported. For example, returning a function or a
JQuery selector from a wrapped function won’t work.

JavaScript → Lua conversion rules:

JavaScript

Lua

string

string

number

number

boolean

boolean

Object

table

Array

table

undefined

nil

null

"" (an empty string)

Date

string: date’s ISO8601 representation, e.g. 1958-05-21T10:12:00Z

RegExp

table {_jstype='RegExp',caseSensitive=true/false,pattern='my-regexp'}

function

an empty table {} (don’t rely on it)

Function arguments and return values are passed by value. For example,
if you modify an argument from inside a JavaScript function then the caller
Lua code won’t see the changes, and if you return a global JS object and modify
it in Lua then object won’t be changed in webpage context.

Note

The rule of thumb: if an argument or a return value can be serialized
via JSON, then it is fine.

If a JavaScript function throws an error, it is re-throwed as a Lua error.
To handle errors it is better to use JavaScript try/catch because some of the
information about the error can be lost in JavaScript → Lua conversion.

Nothing prevents us from taking multiple HTML snapshots. For example, let’s
visit first 10 pages on a website, and for each page store
initial HTML snapshot and an HTML snapshot after waiting 0.5s:

-- Given an url, this function returns a table with-- two HTML snapshots: HTML right after page is loaded,-- and HTML after waiting 0.5s.functionpage_info(splash,url)localok,msg=splash:go(url)ifnotokthenreturn{ok=false,reason=msg}endlocalres={before=splash:html()}assert(splash:wait(0.5))-- this shouldn't fail, so we wrap it in assertres.after=splash:html()-- the same as res["after"] = splash:html()res.ok=truereturnresend-- visit first 10 http://example.com/pages/<num> pages,-- return their html snapshotsfunctionmain(splash)localresult={}fori=1,10dolocalurl="http://example.com/pages/"..page_numresult[i]=page_info(splash,url)endreturnresultend

width and height arguments set a size of the resulting image,
not a size of an area screenshot is taken of. For example, if the viewport
is 1024px wide then splash:png{width=100} will return a screenshot
of the whole viewport, but an image will be downscaled to 100px width.

Returns: information about pages loaded, events happened,
network requests sent and responses received in HAR format.

If your script returns the result of splash:har() in a top-level
"har" key then Splash UI will give you a nice diagram with network
information (similar to “Network” tabs in Firefox or Chrome developer tools):

By default, images are enabled. Disabling of the images can save a lot
of network traffic (usually around ~50%) and make rendering faster.
Note that this option can affect the JavaScript code inside page:
disabling of the images may change sizes and positions of DOM elements,
and scripts may read and use them.

Splash uses in-memory cache; cached images will be displayed
even when images are disabled. So if you load a page, then disable images,
then load a new page, then likely first page will display all images
and second page will display some images (the ones common with the first page).
Splash cache is shared between scripts executed in the same process, so you
can see some images even if they are disabled at the beginning of the script.

size - string, width and height of the viewport.
Format is "<width>x<heigth>", e.g. "800x600".
It also accepts "full" as a value; "full" means that the viewport size
will be auto-detected to fit the whole page (possibly very tall).

Returns: two numbers: width and height the viewport is set to, in pixels.

splash:set_viewport("full") should be called only after page
is loaded, and some time passed after that (use splash:wait). This is
an unfortunate restriction, but it seems that this is the only
way to make rendering work reliably with size=”full”.