Node.js-用于Node.js的Chrome调试协议接口

  • e7_703535
    了解作者
  • 159KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-03 02:48
    上传日期
用于Node.js的Chrome调试协议接口
Node.js-用于Node.js的Chrome调试协议接口.zip
  • chrome-remote-interface-master
  • .github
  • ISSUE_TEMPLATE.md
    745B
  • scripts
  • update-protocol.sh
    541B
  • run-tests.sh
    432B
  • run-linter.sh
    66B
  • lib
  • chrome.js
    9.7KB
  • devtools.js
    3.5KB
  • defaults.js
    78B
  • external-request.js
    1.3KB
  • protocol.json
    799.6KB
  • websocket-wrapper.js
    894B
  • api.js
    2.4KB
  • test
  • devtools.js
    9.3KB
  • send.js
    5.1KB
  • close.js
    1.2KB
  • connect.js
    8.3KB
  • event.js
    3KB
  • bin
  • client.js
    10.4KB
  • .eslintrc.json
    1.1KB
  • webpack.config.js
    596B
  • .babelrc
    41B
  • .travis.yml
    624B
  • LICENSE
    1.1KB
  • README.md
    28.4KB
  • .gitignore
    50B
  • index.js
    1KB
  • .eslintignore
    72B
  • package-lock.json
    256.9KB
  • package.json
    1.6KB
内容介绍
# chrome-remote-interface [![Build Status][]][travis] [Build Status]: https://travis-ci.org/cyrus-and/chrome-remote-interface.svg?branch=master [travis]: https://travis-ci.org/cyrus-and/chrome-remote-interface [Chrome Debugging Protocol] interface that helps to instrument Chrome (or any other suitable [implementation](#implementations)) by providing a simple abstraction of commands and notifications using a straightforward JavaScript API. This module is one of the many [third-party protocol clients][3rd-party]. [3rd-party]: https://developer.chrome.com/devtools/docs/debugging-clients#chrome-remote-interface ## Sample API usage The following snippet loads `https://github.com` and dumps every request made: ```js const CDP = require('chrome-remote-interface'); async function example() { let client; try { // connect to endpoint client = await CDP(); // extract domains const {Network, Page} = client; // setup handlers Network.requestWillBeSent((params) => { console.log(params.request.url); }); // enable events then start! await Network.enable(); await Page.enable(); await Page.navigate({url: 'https://github.com'}); await Page.loadEventFired(); } catch (err) { console.error(err); } finally { if (client) { await client.close(); } } } example(); ``` Find more examples in the [wiki]. You may also want to take a look at the [FAQ]. [wiki]: https://github.com/cyrus-and/chrome-remote-interface/wiki [async-await-example]: https://github.com/cyrus-and/chrome-remote-interface/wiki/Async-await-example [FAQ]: https://github.com/cyrus-and/chrome-remote-interface#faq ## Installation npm install chrome-remote-interface Install globally (`-g`) to just use the [bundled client](#bundled-client). ## Implementations This module should work with every application implementing the [Chrome Debugging Protocol]. In particular, it has been tested against the following implementations: Implementation | Protocol version | [Protocol] | [List] | [New] | [Activate] | [Close] | [Version] ---------------------------|--------------------|------------|--------|-------|------------|---------|----------- [Google Chrome][1.1] | [tip-of-tree][1.2] | yes¹ | yes | yes | yes | yes | yes [Opera][2.1] | [tip-of-tree][2.2] | yes | yes | yes | yes | yes | yes [Node.js][3.1] ([v6.3.0]+) | [node][3.2] | yes | no | no | no | no | yes [Safari (iOS)][4.1] | [*partial*][4.2] | no | yes | no | no | no | no [Microsoft Edge][5.1] | [*partial*][5.2] | yes | yes | no | no | no | yes ¹ Not available on [Chrome for Android][chrome-mobile-protocol]. [chrome-mobile-protocol]: https://bugs.chromium.org/p/chromium/issues/detail?id=824626#c4 [1.1]: #chromechromium [1.2]: https://chromedevtools.github.io/devtools-protocol/tot/ [2.1]: #opera [2.2]: https://chromedevtools.github.io/devtools-protocol/tot/ [3.1]: #nodejs [3.2]: https://chromedevtools.github.io/devtools-protocol/v8/ [4.1]: #safari-ios [4.2]: http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/inspector/protocol [5.1]: #edge [5.2]: https://docs.microsoft.com/en-us/microsoft-edge/devtools-protocol/0.1/domains/ [v6.3.0]: https://nodejs.org/en/blog/release/v6.3.0/ [Protocol]: #cdpprotocoloptions-callback [List]: #cdplistoptions-callback [New]: #cdpnewoptions-callback [Activate]: #cdpactivateoptions-callback [Close]: #cdpcloseoptions-callback [Version]: #cdpversionoptions-callback The meaning of *target* varies according to the implementation, for example, each Chrome tab represents a target whereas for Node.js a target is the currently inspected script. ## Setup An instance of either Chrome itself or another implementation needs to be running on a known port in order to use this module (defaults to `localhost:9222`). ### Chrome/Chromium #### Desktop Start Chrome with the `--remote-debugging-port` option, for example: google-chrome --remote-debugging-port=9222 ##### Headless Since version 59, additionally use the `--headless` option, for example: google-chrome --headless --remote-debugging-port=9222 #### Android Plug the device and enable the [port forwarding][adb], for example: adb forward tcp:9222 localabstract:chrome_devtools_remote [adb]: https://developer.chrome.com/devtools/docs/remote-debugging-legacy ##### WebView In order to be inspectable, a WebView must be [configured for debugging][webview] and the corresponding process ID must be known. There are several ways to obtain it, for example: adb shell grep -a webview_devtools_remote /proc/net/unix Finally, port forwarding can be enabled as follows: adb forward tcp:9222 localabstract:webview_devtools_remote_<pid> [webview]: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews#configure_webviews_for_debugging ### Opera Start Opera with the `--remote-debugging-port` option, for example: opera --remote-debugging-port=9222 ### Node.js Start Node.js with the `--inspect` option, for example: node --inspect=9222 script.js ### Safari (iOS) Install and run the [iOS WebKit Debug Proxy][iwdp]. Then use it with the `local` option set to `true` to use the local version of the protocol or pass a custom descriptor upon connection (`protocol` option). [iwdp]: https://github.com/google/ios-webkit-debug-proxy ### Edge Start Edge with the `--devtools-server-port` option, for example: MicrosoftEdge.exe --devtools-server-port 9222 about:blank Please find more information [here][edge-devtools]. [edge-devtools]: https://docs.microsoft.com/en-us/microsoft-edge/devtools-protocol/ ## Bundled client This module comes with a bundled client application that can be used to interactively control a remote instance. ### Target management The bundled client exposes subcommands to interact with the HTTP frontend (e.g., [List](#cdplistoptions-callback), [New](#cdpnewoptions-callback), etc.), run with `--help` to display the list of available options. Here are some examples: ```javascript $ chrome-remote-interface new 'http://example.com' { "description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/b049bb56-de7d-424c-a331-6ae44cf7ae01", "id": "b049bb56-de7d-424c-a331-6ae44cf7ae01", "thumbnailUrl": "/thumb/b049bb56-de7d-424c-a331-6ae44cf7ae01", "title": "", "type": "page", "url": "http://example.com/", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/b049bb56-de7d-424c-a331-6ae44cf7ae01" } $ chrome-remote-interface close 'b049bb56-de7d-424c-a331-6ae44cf7ae01' ``` ### Inspection Using the `inspect` subcommand it is possible to perform [command execution](#clientdomainmethodparams-callback) and [event binding](#clientdomaineventcallback) in a REPL fashion. But unlike the regular API, events never return a promise, if the callback is omitted a default implementation is provided which allows to toggle the handler. Remember that the REPL interface provides completion. Here is a sample session: ```javascript $ chrome-remote-interface inspect >>> Runtime.evaluate({expression: 'window.location.toString()'}) ... { result: { type: 'string', value: 'about:blank' } } >>> Page.enable() ... {} >>> Page.loadEventFired() // registered { 'Page.loadEventFired': true } >>> Page.loadEventFired() // unregistered { 'Page.loadEventFired': false } >>> Page.loadEventFired() // registered { 'Page.loadEventFired': true } >>> Page.navigate({url: 'https://github.com'}) ... { frameId: '15174.1' } { 'Page.loadEventFired': { timestamp: 46427.780513 } } >>> Runtime.evaluate({expression: 'window.location.toString()'}) ... { result: { type: 'string', value: 'https://github.com/' } } ``` ## Embedded documentation
评论
    相关推荐
    • puppeteer:无头的Chrome Node.js API
      Puppeteer是一个Node库,它提供了高级API来通过控制Chrome或Chromium。 Puppeteer默认情况下运行,但可以配置为运行完整(无头)的Chrome或Chromium。 我能做什么? 您可以在浏览器中手动执行的大多数操作都可以...
    • 木偶:无头的Chrome Node.js API
      Puppeteer是一个Node库,它提供了高级API来通过控制Chrome或Chromium。 Puppeteer默认情况下运行,但可以配置为运行完整(无头)的Chrome或Chromium。 我能做些什么? 您可以在浏览器中手动执行的大多数操作都可以...
    • Puppeteer:无头的Chrome Node.js API-开源
      Puppeteer是一个无头节点库,提供了用于通过DevTools协议控制Chromium或Chrome的高级API。 它需要零设置,并与最适合它的Chromium版本捆绑在一起。 默认情况下,Puppeteer是无头的,因此运行起来很快。 但是,也可以...
    • Puppeteer:无头的Chrome Node.js API-开源
      Puppeteer是一个无头节点库,提供了用于通过DevTools协议控制Chromium或Chrome的高级API。 它需要零设置,并与最适合它的Chromium版本捆绑在一起。 默认情况下,Puppeteer是无头的,因此运行起来很快。 但是,也可以...
    • Node.js-Tutorial:Node.js
      Node.js:教程 ... - Runs on top of the V8 JavaScript Runtime (same that is running on the Chrome browser) What can you build? - Web socket Server - File Upload client - Ad Server - Real
    • Puppeteer Headless Chrome Node.js API-Node.js开发
      Puppeteer是一个Node库,它提供了高级API来通过DevTools协议控制Chrome或Chromium。 Puppeteer默认情况下无头运行,但可以配置为运行完整(无头)的Chrome或Chromium。 Puppeteer是一个Node库,它提供了高级API来...
    • sinon-chrome, 使用 node.js 测试 Chrome 扩展.zip
      sinon-chrome, 使用 node.js 测试 Chrome 扩展 sinonsinon chrome是 单元测试 Chromium 和 Firefox 扩展和应用的helper 工具。 它使用sinon存根模拟所有扩展 api,允许你在 node.js 中运行测试而无需实际浏览器。...
    • Node.js-inspect-process使用chrome-devtools用于Node.js简单调试的工具
      inspect-process:使用chrome-devtools用于Node.js简单调试的工具
    • node.js:node.js连接
      node.js 来自Monggodb mongojs的node.js连接
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等