-
Notifications
You must be signed in to change notification settings - Fork 1
yappie/chrome-remote-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Google Chrome Remote Shell is basically API for running Google Chrome. It allows you to connect to Google Chrome and run javascript instructions on your instance, like opening windows and probably controlling DOM elements. This is a Python library for controlling Google Chrome. First run: $ google-chrome --remote-shell-port=9222 CAUTION: External users might connect to your Google Chrome after running this and run stuff in Chrome, so use firewall. WARNING: You SHOULD have some real web page open in Chrome before trying to evaluate expressions (not some extension page, otherwise sometimes remote shell waits indefinitely), so even better run: $ google-chrome --remote-shell-port=9222 http://google.com/ Then you can use ChromeRemoteShell form Python: from ChromeRemoteShell import ChromeRemoteShell crs = ChromeRemoteShell() # crs.verbose = True # set .verbose = True to see all communications with Chrome Remote Shell # Get all Tabs tab = crs.tabs()[0] print tab # crs.v8_evaluate_js() doesn't return anything (by design [1], see below for # expressions to get things back) tab.v8_evaluate_js('window.open("http://www.google.com/webhp ");') # A space here was not needed (it's here due to bug in GitHub URL parsing) # Give it a time to open import time; time.sleep(.2) # Find new tab tab = crs.tab_by_url('http://www.google.com/webhp') # Attach to V8 engine debugger tab.v8_attach() # Evaluate expression 1+2 print tab.v8_eval_expr('1+2') # prints 3 # Error handling 1+x (x is undefined) try: tab.v8_eval_expr('1+x') # raises Exception with description except Exception: pass # Control dom with document.* tab.v8_evaluate_js('document.write("This was written with ' 'ChromeRemoteShell");') # Detach from V8 tab.v8_detach() NOT IMPLEMENTED: * Events * seq numbers and checking for correct seq numbers External reading about what this is: * [1] http://code.google.com/p/chromedevtools/wiki/ChromeDevToolsProtocol * http://code.google.com/p/v8/wiki/DebuggerProtocol Author: Slava V <bomboze@gmail.com> License: New BSD
About
Chrome Remote Shell library for Python (including evaluations)
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published