Skip to content

Commit

Permalink
html5_media HTTP API argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Feb 14, 2018
1 parent f7be8e6 commit 0699164
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ load_args : JSON object or a string : optional
and cache is cleared after each Splash restart. In other words, storage
is not persistent; client should be ready to re-send the arguments.

.. _arg-html5-media:

html5_media : integer : optional
Whether to enable HTML5 media (e.g. ``<video>`` tags playback).
Possible values are ``1`` (enable) and ``0`` (disable). Default is 0.

HTML5 media is currently disabled by default because it may cause
instability. Splash may enable it by default in future, so pass
``html5_media=0`` explicitly if you don't want HTML5 media.

See also: :ref:`splash-html5-media-enabled`.


Examples
~~~~~~~~

Expand Down
14 changes: 9 additions & 5 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ Common reasons:
(e.g. ``docker run -it -p8050:8050 scrapinghub/splash -v2``),
noting what resources are downloaded last, and filtering them out
using :ref:`splash-on-request` or :ref:`request filters`.
* Some of the crashes can be solved by disabling
:ref:`splash-html5-media-enabled` (note it is disabled by default).
* Some of the crashes can be solved by disabling HTML 5 media
(:ref:`splash-html5-media-enabled` property or
:ref:`html5_media <arg-html5-media>` HTTP API argument) - note it is
disabled by default.
* Website may show a different content based on User-Agent header or based
on IP address. Use :ref:`splash-set-user-agent` to change the default
User-Agent header. If you're running Splash in a cloud and not getting good
Expand All @@ -291,10 +293,12 @@ Common reasons:
* Website requires Flash. You can enable it using
:ref:`splash-plugins-enabled`.
* Website requires IndexedDB_. Enable it using :ref:`splash-indexeddb-enabled`.
* If there is no video or other media, use :ref:`splash-html5-media-enabled`
or :ref:`splash-plugins-enabled` to enable HTML5 media or Flash.
* If there is no video or other media, use :ref:`html5_media <arg-html5-media>`
Splash HTTP argument or :ref:`splash-html5-media-enabled` property to enable
HTML5 media, or :ref:`splash-plugins-enabled` to enable Flash.
* Website has compatibility issues with Webkit version Splash is using.
A quick way to check it is to try opening a page in Safari.
A quick (though not precise) way to check it is to try opening a page
in Safari.

If you have troubles making Splash work, consider asking a question
at https://stackoverflow.com. If you think it is a Splash bug,
Expand Down
2 changes: 2 additions & 0 deletions docs/scripting-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ to enable it.
option may change to ``true`` in future. Set it to ``false`` explicitly
in a script if you don't want HTML5 media.

See also: :ref:`html5_media <arg-html5-media>` HTTP API argument.

.. _splash-media-source-enabled:

splash.media_source_enabled
Expand Down
4 changes: 3 additions & 1 deletion splash/qtrender.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class DefaultRenderScript(RenderScript):
def start(self, url, baseurl=None, wait=None, viewport=None,
js_source=None, js_profile=None, images=None, console=False,
headers=None, http_method='GET', body=None,
render_all=False, resource_timeout=None, response_body=False):
render_all=False, resource_timeout=None, response_body=False,
html5_media=False):

self.url = url
self.wait_time = defaults.WAIT_TIME if wait is None else wait
Expand All @@ -95,6 +96,7 @@ def start(self, url, baseurl=None, wait=None, viewport=None,
self.tab.set_viewport(self.viewport)

self.tab.set_response_body_enabled(response_body)
self.tab.set_html5_media_enabled(html5_media)

self.tab.go(
url=url,
Expand Down
4 changes: 4 additions & 0 deletions splash/render_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def get_forbidden_content_types(self):
content_types = list(filter(None, content_types.split(',')))
return content_types

def get_html5_media(self):
return self._get_bool("html5_media", defaults.HTML5_MEDIA_ENABLED)

def get_common_params(self, js_profiles_path):
wait = self.get_wait()
return {
Expand All @@ -363,6 +366,7 @@ def get_common_params(self, js_profiles_path):
'js_source': self.get_js_source(),
'http_method': self.get_http_method(),
'body': self.get_body(),
'html5_media': self.get_html5_media(),
# 'lua': self.get_lua(),
}

Expand Down
22 changes: 22 additions & 0 deletions splash/tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,28 @@ def test_result_encoding(self):
self.assertTrue(u'проверка' in html)
self.assertTrue(u'1251' in html)

def test_html5_enabled_default(self):
self.assertEqual(self._video_is_enabled({}),
defaults.HTML5_MEDIA_ENABLED)

def test_html5_enabled_on_off(self):
self.assertFalse(self._video_is_enabled({'html5_media': 0}))
self.assertTrue(self._video_is_enabled({'html5_media': 1}))

def _video_is_enabled(self, query):
HTML5_VIDEO_SUPPORTED_JS = """
!!document.createElement('video').canPlayType
""".strip()
_query = {
'url': self.mockurl('jsrender'),
'script': 1,
'js_source': HTML5_VIDEO_SUPPORTED_JS
}
_query.update(query)
r = self.request(_query)
self.assertStatusCode(r, 200)
return bool(r.json().get('script', False))

def assertFieldsInResponse(self, res, fields):
for key in fields:
self.assertTrue(key in res, "%s is not in response" % key)
Expand Down

0 comments on commit 0699164

Please sign in to comment.