【问题标题】:VSCODE: No debug adapter, can not send 'variables'"VSCODE:没有调试适配器,不能发送“变量””
【发布时间】:2020-09-01 04:16:41
【问题描述】:

我开始使用 pupeteer 和 node 并在 win 10 中使用 vscode。我正在尝试登录一个站点并抓取一个表。到目前为止,我有:

(async () => {

const browser = await puppeteer.launch({
  headless: false,
});
var page = await browser.newPage();
await page.goto('thesite.com/login/');

await page.click(USERNAME_SELECTOR);

await page.keyboard.type(CREDS.username);

await page.click(PASSWORD_SELECTOR);
await page.keyboard.type(CREDS.password);

await page.click(BUTTON_SELECTOR);
await page.waitForNavigation();

const TABLE_ROW_SELECTOR = '.gv-container.gv-container-133 > table > tbody';
await page.waitForSelector(TABLE_ROW_SELECTOR);

await page.waitForSelector(TABLE_ROW_SELECTOR);


await page.screenshot({ path: 'example.png' });  
const data = await page.evaluate(SELECTOR => document.querySelectorAll(SELECTOR), TABLE_ROW_SELECTOR);




await browser.close();
})();

这主要是有效的。但是在我的控制台中,我看到了一个对象列表,但据我所知没有任何值。这是最好的对象:

0:Object {}
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}
__defineGetter__:function __defineGetter__() { … }
__defineSetter__:function __defineSetter__() { … }
__lookupGetter__:function __lookupGetter__() { … }
__lookupSetter__:function __lookupSetter__() { … }
constructor:function Object() { … }
hasOwnProperty:function hasOwnProperty() { … }
No debug adapter, can not send 'variables'
isPrototypeOf:function isPrototypeOf() { … }
No debug adapter, can not send 'variables'

“No debug adapter, can't send 'variables'”是什么意思?

编辑:

我更新到最新的 vscode 并检查所有扩展是否都已更新。现在当我运行启动程序时

E:\nodejs\node.exe --inspect-brk=27108 index.js 
Debugger listening on ws://127.0.0.1:27108/e5928c71-370c-  4111-9ec3-77bb2cd85075
For help, see: https://nodejs.org/en/docs/inspector
(node:12844) ExperimentalWarning: The fs.promises API is experimental
warning.js:18
Array(25) [ElementHandle, ElementHandle, ElementHandle, ElementHandle,    ElementHandle, ElementHandle, ElementHandle, ElementHandle, …]
index.js:64
length:25
__proto__:Array(0) [, …]
concat:function concat() { … }
[[Scopes]]:Scopes[0]
arguments:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

知道这意味着什么吗?

【问题讨论】:

  • 调试适配器是连接调试器 API 和 VSC API 的工具。你能调试其他(简单)节点程序吗?
  • 我以前从未使用过节点。我有一些客户端js经验,但以前主要在服务器端使用python。
  • 按照 vsc 文档中的节点教程/设置进行操作
  • 好的,调试器的行为与教程中的完全一样..
  • 那么您的 webscraper 项目的设置与示例节点项目不同

标签: javascript node.js visual-studio-code puppeteer


【解决方案1】:

你也可以试试:

“输出捕获”:“标准”

在您的 launch.json 中

Here is reference on Github

【讨论】:

  • 很好地保留了调试控制台中的所有输出(而不是像 "console": "integratedTerminal" 选项那样污染终端)
  • 很高兴它以您期望的方式提供了帮助。 :)
【解决方案2】:

我在尝试使用integratedConsole 而不是integratedTerminalexternalTerminal 作为我在launch.json 中的节点配置的一部分时遇到了这个问题:

将其设置回:

"console": "integratedTerminal"

修复它。只花了一个小时就弄清楚了。请参阅docs 了解更多信息。

【讨论】:

  • 嘿,“console”:“integratedTerminal”这是launch.json中的第一级配置还是其他?
  • docs 解释它的去向。
  • @http8086 粘贴在program之后。
【解决方案3】:

发生这种情况的原因是调试器在代码执行结束后停止。然后没有更多的调试适配器可用于发送变量。我所做的是在代码执行的底部添加一个额外的行,并在其上设置一个断点。它不漂亮,但它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2022-11-05
    • 2021-01-15
    • 2021-10-23
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多