All Projects → pokemonish → chrome_remote_interface_python

pokemonish / chrome_remote_interface_python

Licence: other
Chrome Debugging Protocol interface for Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to chrome remote interface python

Serverless Chrome
🌐 Run headless Chrome/Chromium on AWS Lambda
Stars: ✭ 2,625 (+2376.42%)
Mutual labels:  chrome-debugging-protocol
Vscode Chrome Debug
Debug your JavaScript code running in Google Chrome from VS Code.
Stars: ✭ 2,126 (+1905.66%)
Mutual labels:  chrome-debugging-protocol
Chromedp
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.
Stars: ✭ 7,057 (+6557.55%)
Mutual labels:  chrome-debugging-protocol
Chrome Remote Interface
Chrome Debugging Protocol interface for Node.js
Stars: ✭ 3,603 (+3299.06%)
Mutual labels:  chrome-debugging-protocol
chrome-remote-interface
Elixir Client for the Chrome Debugger Protocol
Stars: ✭ 56 (-47.17%)
Mutual labels:  chrome-debugging-protocol
node-headless-chrome
⚠️ 🚧 Install precompiled versions of the Chromium/Chrome headless shell using npm or yarn
Stars: ✭ 20 (-81.13%)
Mutual labels:  chrome-debugging-protocol
vscode-android-webview-debug
Debug your JavaScript code running in WebViews on any Android device from VS Code.
Stars: ✭ 18 (-83.02%)
Mutual labels:  chrome-debugging-protocol
simplechrome
Webrecorders DevTools Protocol Automation Library
Stars: ✭ 16 (-84.91%)
Mutual labels:  chrome-debugging-protocol

chrome-remote-interface-python

Chrome Debugging Protocol interface that helps to instrument Chrome (or any other suitable implementation) by providing a simple abstraction of commands and notifications using a straightforward Python API.

This module is one of the many third-party protocol clients.

It is only for Python 3.5 for now

Sample API usage

The following snippet loads https://github.com and prints every response body length:

import asyncio
import chrome_remote_interface

if __name__ == '__main__':
    class callbacks:
        async def start(tabs):
            await tabs.add()
        async def tab_start(tabs, tab):
            await tab.Page.enable()
            await tab.Network.enable()
            await tab.Page.navigate(url='http://github.com')
        async def network__loading_finished(tabs, tab, requestId, **kwargs):
            try:
                body = tabs.helpers.old_helpers.unpack_response_body(await tab.Network.get_response_body(requestId=requestId))
                print('body length:', len(body))
            except tabs.FailResponse as e:
                print('fail:', e)
        async def page__frame_stopped_loading(tabs, tab, **kwargs):
            print('finish')
            tabs.terminate()
        async def any(tabs, tab, callback_name, parameters):
            pass
            # print('Unknown event fired', callback_name)

    asyncio.get_event_loop().run_until_complete(chrome_remote_interface.Tabs.run('localhost', 9222, callbacks))

We use these types of callbacks:

  • start(tabs) - fired on the start.
  • tab_start(tabs, tab, manual) - fired on tab create.
  • network__response_received(tabs, tab, **kwargs) - callback for chrome Network.responseReceived event.
  • any(tabs, tab, callback_name, parameters) - fallback which fired when there is no callback found.
  • tab_close(tabs, tab) - fired when tab is closed
  • tab_suicide(tabs, tab) - fired when tab is closed without your wish (and socket too)
  • close(tabs) - fired when all tabs are closed

We can add tab using method tabs.add() and remove it with tabs[n].remove() or tab.remove().

Each method can throw FailReponse exception when something goes wrong.

You can terminate your programm by calling tabs.terminate().

Installation

git clone https://github.com/wasiher/chrome-remote-interface-python.git
python3 setup.py install

Setup (all description from here)

An instance of either Chrome itself or another implementation needs to be running on a known port in order to use this module (defaults to localhost:9222).

Chrome/Chromium

Desktop

Start Chrome with the --remote-debugging-port option, for example:

google-chrome --remote-debugging-port=9222
Headless

Since version 57, additionally use the --headless option, for example:

google-chrome --headless --remote-debugging-port=9222

Please note that currently the DevTools methods are not properly supported in headless mode; use the Target domain instead. See #83 and #84 for more information.

Android

Plug the device and enable the port forwarding, for example:

adb forward tcp:9222 localabstract:chrome_devtools_remote
WebView

In order to be inspectable, a WebView must be configured for debugging and the corresponding process ID must be known. There are several ways to obtain it, for example:

adb shell grep -a webview_devtools_remote /proc/net/unix

Finally, port forwarding can be enabled as follows:

adb forward tcp:9222 localabstract:webview_devtools_remote_<pid>

Edge

Install and run the Edge Diagnostics Adapter.

Node.js

Start Node.js with the --inspect option, for example:

node --inspect=9222 script.js

Safari (iOS)

Install and run the iOS WebKit Debug Proxy.

Chrome Debugging Protocol versions

You can update it using this way (It will be downloaded automatically first time)

import chrome_remote_interface
chrome_remote_interface.Protocol.update_protocol()

Protocols are loaded from here and here

Contributors

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].