{"id":15676497,"url":"https://github.com/gildas-lormeau/simple-cdp","last_synced_at":"2025-04-16T05:01:53.609Z","repository":{"id":225677809,"uuid":"766568990","full_name":"gildas-lormeau/simple-cdp","owner":"gildas-lormeau","description":"Lightweight JavaScript library to interact with Chromium-based browsers via the Chrome DevTools Protocol","archived":false,"fork":false,"pushed_at":"2024-05-12T22:47:31.000Z","size":104,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T05:03:12.380Z","etag":null,"topics":["browser-automation","bun","cdp","chrome-devtools-protocol","deno"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gildas-lormeau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-03T16:18:18.000Z","updated_at":"2024-12-11T10:26:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"768791e6-011c-49fc-870d-df8bc9bd90cf","html_url":"https://github.com/gildas-lormeau/simple-cdp","commit_stats":{"total_commits":231,"total_committers":1,"mean_commits":231.0,"dds":0.0,"last_synced_commit":"314d8eb309c3e2dbded1cc051434b651dba68f25"},"previous_names":["gildas-lormeau/simple-cdp"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fsimple-cdp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fsimple-cdp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fsimple-cdp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fsimple-cdp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gildas-lormeau","download_url":"https://codeload.github.com/gildas-lormeau/simple-cdp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249199772,"owners_count":21228994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser-automation","bun","cdp","chrome-devtools-protocol","deno"],"created_at":"2024-10-03T16:02:19.141Z","updated_at":"2025-04-16T05:01:53.567Z","avatar_url":"https://github.com/gildas-lormeau.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nsimple-cdp is a JavaScript library to interact with the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/).\n\nThe implementation uses [Proxy](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy) objects to expose APIs. This makes it very light (around [250 lines of code](https://github.com/gildas-lormeau/simple-cdp/blob/main/mod.js)) and independent of protocol evolutions.\n\n# Install\n\nYou can install the library:\n\n- from JSR:\n\n```sh\ndeno add @simple-cdp/simple-cdp\n```\n\n- from NPM:\n\n```sh\nnpm install simple-cdp\n```\n\n# Usage example\n\nStart a Chromium-based browser with the switch `--remote-debugging-port=9222` and run the script below.\n```js\n// import the module (replace with \"simple-cdp\" if using NPM)\nimport { createTarget, CDP } from \"@simple-cdp/simple-cdp\";\n\n// navigate to https://example.com\nconst url = \"https://example.com\";\nconst targetInfo = await createTarget(url);\n\n// create a CDP instance for the target\nconst cdp = new CDP(targetInfo);\n\n// enable \"Runtime\" domain\nawait cdp.Runtime.enable();\n\n// evaluate JavaScript expression\nconst expression = \"41 + 1\";\nconst { result } = await cdp.Runtime.evaluate({ expression });\n\n// display result in the console (i.e. 42)\nconsole.log(result.value);\n```\n\nYou can also manage the session ID with auto-attached targets.\n```js\n// import the module (replace with \"simple-cdp\" if using NPM)\nimport { cdp } from \"@simple-cdp/simple-cdp\";\n\n// enable auto-attach to new targets\nawait cdp.Target.setAutoAttach({\n  autoAttach: true,\n  flatten: true,\n  waitForDebuggerOnStart: false\n});\n\n// add event listener triggered when a session is attached to a target\ncdp.Target.addEventListener(\"attachedToTarget\", onAttachedToTarget);\n\n// create a new target and navigate to https://example.com\nconst url = \"https://example.com\";\nawait cdp.Target.createTarget({ url });\n\nasync function onAttachedToTarget({ params }) {\n  // get session ID\n  const { sessionId, targetInfo } = params;\n\n  // check if the target is a page\n  if (targetInfo.type === \"page\") {\n    // enable \"Runtime\" domain\n    await cdp.Runtime.enable(null, sessionId);\n\n    // evaluate JavaScript expression\n    const expression = \"41 + 1\";\n    const { result } = await cdp.Runtime.evaluate(\n      { expression }, sessionId);\n\n    // display result in the console (i.e. 42)\n    console.log(result.value);\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgildas-lormeau%2Fsimple-cdp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgildas-lormeau%2Fsimple-cdp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgildas-lormeau%2Fsimple-cdp/lists"}