简体   繁体   English

如何在Google Chrome扩展程序中获取node.js进程的调试目标信息?

[英]How to get the debugging target information for a node.js process in a Google Chrome extension?

I would like to write a Chrome extension that uses the chrome.debugger API to attach to a node.js process started with "--inspect", in order to set breakpoints and control execution of the node process. 我想编写一个Chrome扩展程序,该程序使用chrome.debugger API附加到以“ --inspect”开头的node.js进程,以便设置断点并控制该节点进程的执行。 I consulted the documentation , and it appears I would use the API chrome.debugger.attach in order to attach the debugging client to the node.js process. 我查阅了文档 ,并且看来我将使用API chrome.debugger.attach来将调试客户端附加到node.js进程。 The attach API accepts as an argument the targetId of the debugging target to attach. 所述attach API接受作为参数调试目标的目标ID附着。 My question is, how can I find the targetId of the Node.js process, which I can pass to attach ? 我的问题是,我怎么能找到Node.js的过程中,我可以传递到的目标ID attach

I attempted to find the node.js debugging target using the chrome.debugger.getTargets API, but the resulting array of targetInfo did not include the node.js process. 我尝试使用chrome.debugger.getTargets API查找node.js调试目标,但最终的targetInfo数组不包含node.js进程。 The node.js process does appear in chrome://inspect, and I am able to use chrome devtools to inspect the process. node.js进程确实出现在chrome:// inspect中,并且我能够使用chrome devtools检查该进程。 I'm wondering if the node.js process does not appear in the targetInfo results because the node.js process is a remote debugging target, whereas all other results in this array were local debugging targets. 我想知道node.js进程是否未出现在targetInfo结果中,因为node.js进程是远程调试目标,而此数组中的所有其他结果都是本地调试目标。

I would appreciate any insight into this. 我将不胜感激。 Thank you. 谢谢。

If you look at how google have retrieved the remote source's. 如果您查看google如何检索远程源。 eg. 例如。 Use inspector inside the chrome://inspect . chrome://inspect使用chrome://inspect

There is a javascript function called populateRemoteTargets inside inspect.js inspect.js有一个名为populateRemoteTargets的javascript函数

On my machine the data parameter been sent is -> 在我的机器上,已发送的数据参数为->

{
  "adbConnected": true,
  "adbModel": "Remote Target",
  "adbSerial": "localhost",
  "browsers": [
    {
      "adbBrowserChromeVersion": 0,
      "adbBrowserName": "Target",
      "adbBrowserUser": "",
      "adbBrowserVersion": "",
      "id": "localhost:9222",
      "pages": [],
      "source": "remote"
    },
    {
      "adbBrowserChromeVersion": 0,
      "adbBrowserName": "Target",
      "adbBrowserUser": "",
      "adbBrowserVersion": "",
      "id": "localhost:9229",
      "pages": [],
      "source": "remote"
    }
  ],
  "id": "device:localhost"
}

Not sure were google store this list, but's it obviously what's stored in the configure dialog. 不确定google是否存储了此列表,但是很明显它存储在配置对话框中。 There may be a way to get this data, not sure. 不确定,可能有一种获取此数据的方法。 If not, you could maybe maintain the list yourself. 如果没有,您可以自己维护列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM