.. _scripting-reference: Splash Scripts Reference ======================== .. note:: While this reference is comprehensive, it can be hard to navigate. If you're just starting, or don't know what you're looking for exactly, check :ref:`splash-lua-api-overview` first. ``splash`` object is passed to ``main`` function as a first argument; via this object a script can control the browser. Think of it as of an API to a single browser tab. Attributes ~~~~~~~~~~ .. _splash-args: splash.args ----------- ``splash.args`` is a table with incoming parameters. It contains merged values from the orignal URL string (GET arguments) and values sent using ``application/json`` POST request. For example, if you passed 'url' argument to a script using HTTP API, then ``splash.args.url`` contains this URL. You can also access ``splash.args`` using second, optional ``args`` argument of the ``main`` function: .. code-block:: lua function main(splash, args) local url = args.url -- ... end The example above is the same as .. code-block:: lua function main(splash) local url = splash.args.url -- ... end Using either ``args`` or :ref:`splash-args` is the preferred way to pass parameters to Splash scripts. An alternative way is to use string formatting to build a script with variables embedded. There are two problems which make :ref:`splash-args` a better solution: 1. data must be escaped somehow, so that it doesn't break a Lua script; 2. embedding variables makes it impossible to use script cache efficiently (see :ref:`save_args ` and :ref:`load_args ` arguments of the HTTP API). .. _splash-js-enabled: splash.js_enabled ----------------- Enable or disable execution of JavaSript code embedded in the page. **Signature:** ``splash.js_enabled = true/false`` JavaScript execution is enabled by default. .. _splash-private-mode-enabled: splash.private_mode_enabled --------------------------- Enable or disable browser's private mode (incognito mode). **Signature:** ``splash.private_mode_enabled = true/false`` Private mode is enabled by default unless you pass flag ``--disable-private-mode`` at Splash startup. Note that if you disable private mode some of the browsing data may persist between requests (it doesn't affect cookies though). See also: :ref:`disable-private-mode`. .. _splash-resource-timeout: splash.resource_timeout ----------------------- Set a default timeout for network requests, in seconds. **Signature:** ``splash.resource_timeout = number`` Example - abort requests to remote resources if they take more than 10 seconds: .. code-block:: lua function main(splash) splash.resource_timeout = 10.0 assert(splash:go(splash.args.url)) return splash:png() end Zero or nil value means "no timeout". Request timeouts set in :ref:`splash-on-request` using ``request:set_timeout`` have a priority over :ref:`splash-resource-timeout`. .. _splash-images-enabled: splash.images_enabled --------------------- Enable/disable images. **Signature:** ``splash.images_enabled = true/false`` 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. Example: .. literalinclude:: ../splash/examples/disable-images.lua :language: lua .. _splash-plugins-enabled: splash.plugins_enabled ---------------------- Enable or disable browser plugins (e.g. Flash). **Signature:** ``splash.plugins_enabled = true/false`` Plugins are disabled by default. .. _splash-response-body-enabled: splash.response_body_enabled ---------------------------- Enable or disable response content tracking. **Signature:** ``splash.response_body_enabled = true/false`` By default Splash doesn't keep bodies of each response in memory, for efficiency reasons. It means that in :ref:`splash-on-response` callbacks :ref:`splash-response-body` attribute is not available, and that response content is not available in HAR_ exports. To make response content available to a Lua script set ``splash.response_body_enabled = true``. Note that :ref:`splash-response-body` is always available in :ref:`splash-http-get` and :ref:`splash-http-post` results, regardless of :ref:`splash-response-body-enabled` option. To enable response content tracking per-request call :ref:`splash-request-enable-response-body` in a :ref:`splash-on-request` callback. .. _splash-scroll-position: splash.scroll_position ---------------------- Get or set current scroll position. **Signature:** ``splash.scroll_position = {x=..., y=...}`` This property allows to get and set current scroll position of the main window. Scrolling outside window content has no effect. For example, if you set ``splash.scroll_position`` to ``{x=-100, y=-100}``, then ``splash.scroll_position`` will likely still be equal to the default ``{x=0, y=0}``. To set scroll position instead of the full form (e.g. ``splash.scroll_position = {x=100, y=200}``) you can also use the short form ``splash.scroll_position = {100, 200}``. Attribute value is always a table with ``x`` and ``y`` keys, even if you set it using the short form. It is also possible to omit coordinates which you don't want to change. For example, ``splash.scroll_position = {y=200}`` sets y to 200 and keeps previous x value. .. _splash-indexeddb-enabled: splash.indexeddb_enabled ------------------------ Enable or disable IndexedDB_. **Signature:** ``splash.indexeddb_enabled = true/false`` IndexedDB is disabled by default. Use ``splash.indexeddb_enabled = true`` to enable it. .. note:: Currently IndexedDB is disabled by default because there are issues with Splash WebKit's implementation. Default value for this option may change to ``true`` in future. .. _IndexedDB: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API .. _splash-webgl-enabled: splash.webgl_enabled -------------------- Enable or disable WebGL_. **Signature:** ``splash.webgl_enabled = true/false`` WebGL is enabled by default. Use ``splash.webgl_enabled = false`` to disable it. .. _WebGL: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API .. _splash-html5-media-enabled: splash.html5_media_enabled -------------------------- Enable or disable HTML5 media, including HTML5 video and audio (e.g. ``