
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
chrome-debugging-client
Advanced tools
An async/await friendly Chrome debugging client with TypeScript support
An async/await friendly Chrome debugging client with TypeScript support, designed with automation in mind.
DEBUG=chrome-debugging-client
const { spawnChrome } = require("chrome-debugging-client");
const { writeFileSync } = require("fs");
main();
async function main() {
const chrome = spawnChrome();
try {
const browser = chrome.connection;
browser.on("error", err => {
// underlying connection error or error dispatching events.
console.error(`connection error ${err.stack}`);
});
const { targetId } = await browser.send("Target.createTarget", {
url: "about:blank",
});
await browser.send("Target.activateTarget", { targetId });
const page = await browser.attachToTarget(targetId);
let buffer = "";
await page.send("HeapProfiler.enable");
page.on("HeapProfiler.addHeapSnapshotChunk", params => {
buffer += params.chunk;
});
await page.send("HeapProfiler.takeHeapSnapshot", {
reportProgress: false,
});
writeFileSync("heapsnapshot.json", buffer);
await browser.send("Target.closeTarget", { targetId });
// graceful browser shutdown
await chrome.close();
} finally {
await chrome.dispose();
}
}
const { spawnWithWebSocket } = require("chrome-debugging-client");
main();
async function main() {
// start node requesting it break on start at debug port that
// is available
const node = await spawnWithWebSocket(process.execPath, [
"--inspect-brk=0",
"-e",
`const obj = {
hello: "world",
};
debugger;
console.log("end");`,
]);
const { connection } = node;
try {
// we requested Node to break on start, so we runIfWaitingForDebugger
// and wait for it to break at the start of our script
await Promise.all([
connection.until("Debugger.paused"),
connection.send("Debugger.enable"),
connection.send("Runtime.enable"),
connection.send("Runtime.runIfWaitingForDebugger"),
]);
// right now we are paused at the start of the script
// resume until debugger statement hit
const [debuggerStatement] = await Promise.all([
connection.until("Debugger.paused"),
connection.send("Debugger.resume"),
]);
// get the call frame of the debugger statement
const [callFrame] = debuggerStatement.callFrames;
const { callFrameId } = callFrame;
// eval obj at the debugger call frame
const { result } = await connection.send(
"Debugger.evaluateOnCallFrame",
{
callFrameId,
expression: "obj",
returnByValue: true,
},
);
console.log(result.value); //= { hello: "world" }
// resume and wait for execution to be done
await Promise.all([
connection.until("Runtime.executionContextDestroyed"),
connection.send("Debugger.resume"),
]);
// Node is still alive here and waiting for the debugger to disconnect
// when we close the websocket after resuming
// Node should exit on its own
node.close();
await node.waitForExit();
} finally {
await node.dispose();
}
}
FAQs
An async/await friendly Chrome debugging client with TypeScript support
We found that chrome-debugging-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.