Skip to content

Repository files navigation

chrome-debugging-client

Build Status

An async/await friendly Chrome debugging client with TypeScript support, designed with automation in mind.

Features:

  • Promise API for async/await (most debugger commands are meant to be sequential).
  • Launches Chrome with a new temp user data folder so Chrome launches an isolated instance. (regardless if you already have Chrome open).
  • Opens an ephemeral remote debugging port so you don't need to configure a port.
  • A TypeScript codegen for API autocomplete and tooltips with documentation for the debugger protocol https://chromedevtools.github.io/devtools-protocol/
  • Cleans up processes and connections at end of session.

Example:

import{createSession}from"chrome-debugging-client";// import protocol domains "1-2", "tot", or "v8"import{HeapProfiler}from"chrome-debugging-client/dist/protocol/tot";createSession(async(session)=>{// spawns a chrome instance with a tmp user data// and the debugger open to an ephemeral portconstprocess=awaitsession.spawn("canary",{additionalArguments: ['--headless'],windowSize: {width: 640,height: 320}});// open the REST API for tabsconstclient=session.createAPIClient("localhost",process.remoteDebuggingPort);consttabs=awaitclient.listTabs();consttab=tabs[0];awaitclient.activateTab(tab.id);// open the debugger protocol// https://chromedevtools.github.io/devtools-protocol/constdebuggerClient=awaitsession.openDebuggingProtocol(tab.webSocketDebuggerUrl);// create the HeapProfiler domain with the debugger protocol clientconstheapProfiler=newHeapProfiler(debuggerClient);awaitheapProfiler.enable();// The domains are optional, this can also be// await debuggerClient.send("HeapProfiler.enable", {})letbuffer="";heapProfiler.addHeapSnapshotChunk=(evt)=>{buffer+=evt.chunk;});awaitheapProfiler.takeHeapSnapshot({reportProgress: false});awaitheapProfiler.disable();returnJSON.parse(buffer);}).then((data)=>{console.log(data.snapshot.meta);}).catch((err)=>{console.error(err);});

customize browser executable path

By default, this tool launches Chrome Canary. It may error if it cannot find the executable. For this and other reasons, you can configure the executable path like so:

// example for macOSletbrowser=awaitsession.spawnBrowser('exact',{executablePath: '/Users/someone/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'});

About

An async / await friendly debugging client for chrome

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages