@@ -0,0 +1,1852 @@
+#!/usr/bin/env python3%0A%0A# https://chromedevtools.github.io/debugger-protocol-viewer/tot/HeapProfiler/%0A%0Aimport json%0A%0Aimport requests%0Aimport selenium%0Aimport websocket%0Afrom devtools.proxy import CHROME_WRAPPER_PATH%0Afrom selenium.webdriver.common.desired_capabilities import DesiredCapabilities%0A%0Aif __name__ == '__main__':%0A    devtools_proxy_port = 9222%0A%0A    desired_capabilities = DesiredCapabilities.CHROME.copy()%0A    desired_capabilities%5B'chromeOptions'%5D = %7B%0A        'binary': CHROME_WRAPPER_PATH,%0A        'args': %5B%0A            '--devtools-proxy-binary=devtools-proxy',%0A            '--devtools-proxy-args=--port %7B%7D'.format(devtools_proxy_port),%0A        %5D%0A    %7D%0A%0A    driver = selenium.webdriver.Chrome(desired_capabilities=desired_capabilities)%0A    try:%0A        tabs = requests.get('http://localhost:%7B%7D/json/list'.format(devtools_proxy_port)).json()%0A        tab = next(tab for tab in tabs if tab.get('type') == 'page')%0A        devtools_url = tab%5B'webSocketDebuggerUrl'%5D%0A        driver.get('https://google.co.uk')%0A%0A        ws = websocket.create_connection(devtools_url)%0A        data = %7B%0A            %22method%22: %22HeapProfiler.enable%22,%0A            %22params%22: %7B%7D,%0A            %22id%22: 0,%0A        %7D%0A        ws.send(json.dumps(data))%0A        ws.recv()%0A%0A        data = %7B%0A            %22method%22: %22HeapProfiler.takeHeapSnapshot%22,%0A            %22params%22: %7B%7D,%0A            %22id%22: 0,%0A        %7D%0A        ws.send(json.dumps(data))%0A%0A        heap_data = ''%0A        while True:%0A            raw_data = ws.recv()%0A            result = json.loads(raw_data)%0A            if result.get('id') == 0:%0A                break%0A            if result.get('method') == 'HeapProfiler.addHeapSnapshotChunk':%0A                heap_data += result%5B'params'%5D%5B'chunk'%5D%0A%0A        ws.close()%0A%0A        with open('example.heapsnapshot', 'w') as f:%0A            f.write(heap_data)%0A    finally:%0A        driver.quit()%0A

Add example for taking heap snapshot