Skip to content

Commit

Permalink
Merge pull request #9 from wnielson/master
Browse files Browse the repository at this point in the history
Added screenshot support
  • Loading branch information
iiSeymour authored May 13, 2017
2 parents 1b117a4 + 7044a61 commit f14b9a8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions chromote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
https://chromedevtools.github.io/devtools-protocol/1-2
"""

import base64
import json
import requests
import websocket
Expand Down Expand Up @@ -77,6 +78,24 @@ def evaluate(self, javascript):
"""
return self._send({"method": "Runtime.evaluate", "params": {"expression": javascript}})

def screenshot(self, format='png', quality=85, fromSurface=False):
"""
Take a screenshot of the page
"""
args = {
"method": "Page.captureScreenshot",
"params": {
"format": format,
"quality": quality,
"fromSurface": fromSurface
}
}
result = self._send(args)
data = json.loads(result)
if data.has_key('error'):
raise ValueError(data['error']['data'])
return base64.b64decode(data.get('result',{}).get('data', ''))

def __str__(self):
return '%s - %s' % (self.title, self.url)

Expand Down

0 comments on commit f14b9a8

Please sign in to comment.