Last active
April 8, 2017 16:27
-
-
Save baongoc124/ab7fab56f9f95363c75ff79b19257b60 to your computer and use it in GitHub Desktop.
web complete script for google chrome/chromium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
from __future__ import print_function | |
# https://github.com/benslk/chrome_remote_shell | |
# should be installed from git. Using PIP to install will only get older, not working version | |
import chrome_remote_shell, json | |
import re | |
shell = chrome_remote_shell.Shell(host='localhost', port=9222) | |
shell.connect(0) | |
navcom = json.dumps({"id":0, "method":"Runtime.evaluate", "params":{"expression": "document.body.innerText"}}) | |
shell.soc.send(navcom) | |
response = json.loads(shell.soc.recv()) | |
data = response['result']['result']['value'] | |
data = set(re.split('\W', data)) | |
data = filter(lambda s: len(s) > 4, data) | |
print(u'\n'.join(data).encode('utf-8').strip()) | |
Does this approach still work for you?
I get an empty result, and the response I get back from the client is
{u'id': 0, u'result': {u'result': {u'type': u'string', u'value': u''}}}`
I believed your approach wasn't working anymore and looked into https://github.com/cyrus-and/chrome-remote-interface as an alternative. I ran
chrome-remote-interface inspect
>>> Runtime.evaluate({expression: 'window.location.toString()'})
{ result:
{ result:
{ type: 'string',
value: 'chrome-extension://bikioccmkafdpakkkcpdbppfkghcmihk/background.html' } } }
>>> Runtime.evaluate({expression: 'window.location.toString()'})
{ result:
{ result:
{ type: 'string',
value: 'chrome-extension://bikioccmkafdpakkkcpdbppfkghcmihk/background.html' } } }
What the ... ? What is that extension? Signal Desktop!
Once I disabled the extension/app everything was working and both chrome_remote_shell and chrome-remote-interface could actually interact with the current page.
Ugh. It worked for a second and now it's reporting empty content again and chrome-remote-interface is reporting another extension. I opened an issue at cyrus-and/chrome-remote-interface#91 maybe they have an idea.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chrome has to be run in with remote debugging enabled at port 9222.