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

next

Added in: v1.59 debugger.next

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

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

用法

Debugger.next();

返回


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();

返回


requestPause

Added in: v1.59 debugger.requestPause

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

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

如果调试器已经暂停,则抛出异常。暂停时请使用 Debugger.next()Debugger.runTo() 进行单步操作。

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

注意,Page.pause() 相当于一个“debugger”语句——它会在调用位置立即暂停执行。相反,Debugger.requestPause() 相当于“在下一条语句暂停”——它配置调试器在执行下一步操作之前暂停。

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

用法

Debugger.requestPause();

返回


resume

Added in: v1.59 debugger.resume

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

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

用法

Debugger.resume();

返回


runTo

Added in: v1.59 debugger.runTo

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

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

用法

Debugger.runTo(location);

参数

  • location Location#

    • setFile String

    • setLine int (optional)

    • setColumn int (optional)

    要暂停的源位置。

返回


事件

🌐 Events

onPausedStateChanged(handler)

Added in: v1.59 debugger.onPausedStateChanged(handler)

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

🌐 Emitted when the debugger pauses or resumes.

用法

Debugger.onPausedStateChanged(handler)