Skip to content

anbuhckr/aiocdp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 

Repository files navigation

aiocdp

GitHub issues GitHub forks GitHub stars GitHub license PyPI - Python Version

Asynchronous Chrome DevTools Protocol Package for access lower level methods in Chrome.

Table of Contents

Installation

To install aiochrome, simply:

$ python3 -m pip install -U git+https://github.com/anbuhckr/aiocdp.git

or from source:

$ python3 setup.py install

Getting Started

#! /usr/bin/env python3

import asyncio
from aiocdp.browser import Browser

async def request_will_be_sent(**kwargs):
    print(f"loading: {kwargs.get('request').get('url')}")

async def main():
    # chrome options
    options = [
        "--disable-gpu",
        "--no-sandbox",
        "--disable-setuid-sandbox",
    ]
    
    # create browser instance with custom options
    browser = Browser(opts=options)

    # register callback if you want
    browser.on('main', 'Network.requestWillBeSent', request_will_be_sent)
    
    # start browser with custom method
    try:
        await browser.start() 
        await browser.send('Network.enable')
        await browser.send('Page.enable')
        await browser.send('Page.navigate', url="https://github.com/anbuhckr/aiocdp")
        
        # wait for loading
        await asyncio.sleep(10)
        
    # handle exception
    except Exception as e:
        print(e)
        pass
        
    # close browser
    await browser.stop()

if __name__ == '__main__':
    asyncio.run(main())      

more methods or events could be found in Chrome DevTools Protocol

Ref