Skip to main content

调试器

用于控制 Playwright 调试器的 API。调试器允许暂停脚本执行并检查页面。通过 BrowserContext.Debugger 获取调试器实例。

🌐 API for controlling the Playwright debugger. The debugger allows pausing script execution and inspecting the page. Obtain the debugger instance via BrowserContext.Debugger.


方法

🌐 Methods

NextAsync

Added in: v1.59 debugger.NextAsync

恢复脚本执行,并在下一个操作前再次暂停。如果调试器未暂停,则抛出异常。

🌐 Resumes script execution and pauses again before the next action. Throws if the debugger is not paused.

用法

await Debugger.NextAsync();

返回


PausedDetails

Added in: v1.59 debugger.PausedDetails

返回有关当前已暂停通话的详细信息。如果调试器未暂停,则返回 null

🌐 Returns details about the currently paused call. Returns null if the debugger is not paused.

用法

Debugger.PausedDetails

返回

  • 暂停的详细信息?#

RequestPauseAsync

Added in: v1.59 debugger.RequestPauseAsync

配置调试器以在执行下一操作之前暂停。

🌐 Configures the debugger to pause before the next action is executed.

如果调试器已经暂停,则会抛出异常。暂停时使用 Debugger.NextAsync()Debugger.RunToAsync() 来执行单步操作。

🌐 Throws if the debugger is already paused. Use Debugger.NextAsync() or Debugger.RunToAsync() to step while paused.

请注意,Page.PauseAsync() 等同于 "debugger" 语句——它会立即在调用位置暂停执行。相反,Debugger.RequestPauseAsync() 等同于 "在下一条语句暂停"——它会配置调试器在下一条操作执行之前暂停。

🌐 Note that Page.PauseAsync() is equivalent to a "debugger" statement — it pauses execution at the call site immediately. On the contrary, Debugger.RequestPauseAsync() is equivalent to "pause on next statement" — it configures the debugger to pause before the next action is executed.

用法

await Debugger.RequestPauseAsync();

返回


ResumeAsync

Added in: v1.59 debugger.ResumeAsync

恢复脚本执行。如果调试器未暂停,则抛出异常。

🌐 Resumes script execution. Throws if the debugger is not paused.

用法

await Debugger.ResumeAsync();

返回


RunToAsync

Added in: v1.59 debugger.RunToAsync

恢复脚本执行,并在操作来自给定源位置时暂停。如果调试器未暂停,则抛出异常。

🌐 Resumes script execution and pauses when an action originates from the given source location. Throws if the debugger is not paused.

用法

await Debugger.RunToAsync(location);

参数

  • location Location#

    要暂停的源位置。

返回


事件

🌐 Events

event PausedStateChanged

Added in: v1.59 debugger.event PausedStateChanged

当调试器暂停或恢复时发出。

🌐 Emitted when the debugger pauses or resumes.

用法

Debugger.PausedStateChanged += async (_, void) => {};