{"id":18710689,"url":"https://github.com/apify/devtools-server","last_synced_at":"2025-11-03T16:30:58.787Z","repository":{"id":44677015,"uuid":"257346354","full_name":"apify/devtools-server","owner":"apify","description":"Runs a simple server that allows you to connect to Chrome DevTools running on dynamic hosts, not only localhost.","archived":false,"fork":false,"pushed_at":"2022-07-25T12:57:12.000Z","size":43,"stargazers_count":15,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-08T19:55:32.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-20T16:50:38.000Z","updated_at":"2024-08-01T18:04:09.000Z","dependencies_parsed_at":"2022-09-07T06:02:42.404Z","dependency_job_id":null,"html_url":"https://github.com/apify/devtools-server","commit_stats":null,"previous_names":["apifytech/devtools-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fdevtools-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fdevtools-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fdevtools-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fdevtools-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apify","download_url":"https://codeload.github.com/apify/devtools-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223515339,"owners_count":17158354,"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":[],"created_at":"2024-11-07T12:35:17.975Z","updated_at":"2025-11-03T16:30:58.747Z","avatar_url":"https://github.com/apify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# devtools-server\nEnables remote connection to DevTools of a Chrome browser running somewhere\non the internet, typically in a Docker container.\n\n```\n\n                         container at some-host.com\n                   |------------------------------------|\n |--------|        |  |----------|        |----------|  |\n | client | \u003c====\u003e |  | devtools |        |  Chrome  |  |\n |--------|        |  |  server  | \u003c====\u003e | DevTools |  |\n                   |  |----------|        |----------|  |\n                   |------------------------------------|\n\n```\nThe client can not connect to Chrome DevTools directly due to security\nlimitations of Chrome, which allows connections only from localhost.\ndevtools-server bridges that connection and serves as a proxy between\nthe client and the Chrome DevTools. Automatically forwarding connections\nto the first open tab, ignoring about:blank.\n\n## Example\n\n```js\nconst server = new DevToolsServer({\n    containerHost: 'some-host.com',\n    devToolsServerPort: 4321,\n});\n\nawait server.start();\n```\n\nServer will now accept connections at `https://some-host.com` and make DevTools frontend available there.\n\n## Use with Puppeteer\n\n```js\nconst DevToolsServer = require('devtools-server');\nconst puppeteer = require('puppeteer');\n\nasync function main() {\n    const browser = await puppeteer.launch({\n        args: ['--remote-debugging-port=9222'],\n    });\n\n    const server = new DevToolsServer({\n        // Using localhost here so you can run\n        // the example on your local machine.\n        containerHost: 'localhost:4321',\n        devToolsServerPort: 4321,\n        insecureConnection: true,\n    });\n\n    await server.start();\n\n    const page = await browser.newPage();\n    await page.goto('https://example.com');\n\n    // Now connect to the server. You will see the page\n    // loaded and DevTools open.\n\n    // This delay is only here to give you enough time to\n    // connect and inspect the page. See debugging section\n    // below for breakpoint use.\n    await page.waitFor(2 * 60 * 1000);\n\n    server.stop();\n    await browser.close();\n}\n\nmain();\n```\n\n### Debugging\nProbably the most common use-case for DevTools is debugging. You can easily extend your scripts with debugging\ncapabilities by enabling the Debugger and adding breakpoints. \n\n```js\n// page is a Puppeteer Page\nconst cdpClient = await page.target().createCDPSession();\nawait cdpClient.send('Debugger.enable');\n\n// adding breakpoints later\n\n// Stops execution in the browser,\n// but this script will keep running.\nawait cdpClient.send('Debugger.pause');\n\n// Stops execution in both browser\n// and this script. Will not continue\n// until the execution is resumed in browser.\nawait page.evaluate(() =\u003e { debugger; });\n```\n\n## Use with Apify\n\nThis library was created to be used with the [`Apify`](https://apify.com) platform\nto enable its users viewing and debugging their scrapers directly in the application UI.\n\nTo access the containers running on the platform, one needs to utilize the APIFY_CONTAINER_URL\nand APIFY_CONTAINER_PORT [environment variables](https://docs.apify.com/actor/run#environment-variables).\nIf you want a better understanding of this library, read\n[how to run a web server on Apify](https://help.apify.com/en/articles/2157629-running-a-web-server).\n\n```js\nconst Apify = require('apify');\nconst { URL } = require('url');\nconst DevToolsServer = require('devtools-server');\n\nApify.main(async () =\u003e {\n    const browser = await Apify.launchPuppeteer({\n        launchOptions: {\n            args: ['--remote-debugging-port=9222'],\n        }\n    });\n\n    const containerHost = new URL(process.env.APIFY_CONTAINER_URL).host;\n    const devToolsServerPort = process.env.APIFY_CONTAINER_PORT;\n\n    const server = new DevToolsServer({ containerHost, devToolsServerPort });\n\n    await server.start();\n\n    const page = await browser.newPage();\n    await page.goto('https://example.com');\n    \n    await page.waitFor(10 * 60 * 1000);\n\n    await browser.close();\n})\n```\n\nDebugging is the same as in the [Debugging](#debugging) section.\n\n### Using with `PuppeteerCrawler`\n\nHere it gets a bit tricky because the crawler will open and close pages on its own. Depending\non your use-case, you'll have to do one or all of those things:\n\n- set `maxConcurrency` to `1` to only use a single tab. Otherwise it gets messy\n- prevent retiring of browsers by setting `retireInstanceAfterRequestCount` high.\n- increase `handlePageTimeoutSecs` to prevent timeouts killing your pages\n- increase `gotoTimeoutSecs` if you use breakpoints before navigation\n- add delays and timeouts inside the `handlePageFunction` to slow things down\n  You can use `page.waitFor(millis)` to create a delay\n- add breakpoints using `await page.evaluate(() =\u003e { debugger; })` to stop execution\n\n#### Example constructor options \n\n```js\nconst puppeteerCrawlerOptions = {\n    ...otherOptions, // such as requestQueue, handlePageFunction...\n    maxConcurrency: 1,\n    handlePageTimeoutSecs: 3600, // 1 hour\n    gotoTimeoutSecs: 3600,\n    launchPuppeteerOptions: {\n        args: ['--remote-debugging-port=9222']\n    },\n    puppeteerPoolOptions: {\n        retireInstanceAfterRequestCount: 10000\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fdevtools-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapify%2Fdevtools-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fdevtools-server/lists"}