Skip to main content
Version: 24.38.0

PageEvent 枚举

🌐 PageEvent enum

页面实例可能触发的所有事件。

🌐 All the events that a page instance may emit.

语法

🌐 Signature

export declare const enum PageEvent

枚举成员

🌐 Enumeration Members

成员

🌐 Member

🌐 Value

描述

🌐 Description

关闭

🌐 Close

"close"

页面关闭时触发。

🌐 Emitted when the page closes.

Console

"console"

当页面中的 JavaScript 调用控制台 API 方法(例如 console.logconsole.dir)时触发。如果页面抛出错误或警告,也会触发。

🌐 Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir. Also emitted if the page throws an error or a warning.

附注

一个 console 事件提供一个 ConsoleMessage,表示已记录的控制台消息。

🌐 A console event provides a ConsoleMessage representing the console message that was logged.

Dialog

"dialog"

当出现 JavaScript 对话框时触发,例如 alertpromptconfirmbeforeunload。Puppeteer 可以通过 Dialog.accept()Dialog.dismiss() 对对话框进行响应。

🌐 Emitted when a JavaScript dialog appears, such as alert, prompt, confirm or beforeunload. Puppeteer can respond to the dialog via Dialog.accept() or Dialog.dismiss().

DOMContentLoaded

"domcontentloaded"

当 JavaScript DOMContentLoaded 事件被分发时触发。

🌐 Emitted when the JavaScript DOMContentLoaded event is dispatched.

错误

🌐 Error

"error"

当页面崩溃时触发。将包含一个 Error

🌐 Emitted when the page crashes. Will contain an Error.

FrameAttached

"frameattached"

当帧被附加时触发。将包含一个 Frame

🌐 Emitted when a frame is attached. Will contain a Frame.

FrameDetached

"framedetached"

当一个框架被分离时触发。将包含一个 Frame

🌐 Emitted when a frame is detached. Will contain a Frame.

FrameNavigated

"framenavigated"

当帧被导航到新 URL 时触发。将包含一个 Frame

🌐 Emitted when a frame is navigated to a new URL. Will contain a Frame.

加载

🌐 Load

"load"

当 JavaScript load 事件被分发时触发。

🌐 Emitted when the JavaScript load event is dispatched.

Metrics

"metrics"

当 JavaScript 代码调用 console.timeStamp 时发出。有关指标列表,请参阅 page.metrics

🌐 Emitted when the JavaScript code makes a call to console.timeStamp. For the list of metrics see page.metrics.

附注

包含一个具有两个属性的对象:

🌐 Contains an object with two properties:

  • title:传递给 console.timeStamp - metrics 的标题:包含指标的键/值对的对象。值将是 number

PageError

"pageerror"

当页面内发生未捕获的异常时触发。包含一个 Error 或类型未知的数据。

🌐 Emitted when an uncaught exception happens within the page. Contains an Error or data of type unknown.

弹出窗口

🌐 Popup

"popup"

当页面打开新选项卡或窗口时触发。

🌐 Emitted when the page opens a new tab or window.

包含一个对应于弹出窗口的页面

🌐 Contains a Page corresponding to the popup window.

要求

🌐 Request

"request"

当页面发出请求且包含 HTTPRequest 时触发。

🌐 Emitted when a page issues a request and contains a HTTPRequest.

附注

该对象是只读的。有关拦截和修改请求,请参阅 Page.setRequestInterception()

🌐 The object is readonly. See Page.setRequestInterception() for intercepting and mutating requests.

RequestFailed

"requestfailed"

当请求失败时触发,例如超时。

🌐 Emitted when a request fails, for example by timing out.

包含一个 HTTPRequest

🌐 Contains a HTTPRequest.

附注

HTTP 错误响应,例如 404 或 503,从 HTTP 的角度来看仍然是成功的响应,因此请求将以 requestfinished 事件完成,而不是以 requestfailed 完成。

🌐 HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with requestfinished event and not with requestfailed.

RequestFinished

"requestfinished"

当请求成功完成时发出。包含一个 HTTPRequest

🌐 Emitted when a request finishes successfully. Contains a HTTPRequest.

RequestServedFromCache

"requestservedfromcache"

当请求最终从缓存加载时触发。包含一个 HTTPRequest

🌐 Emitted when a request ended up loading from cache. Contains a HTTPRequest.

附注

对于某些请求,可能包含未定义。https://crbug.com/750469

🌐 For certain requests, might contain undefined. https://crbug.com/750469

响应

🌐 Response

"response"

当收到响应时发出。包含一个 HTTPResponse

🌐 Emitted when a response is received. Contains a HTTPResponse.

WorkerCreated

"workercreated"

当页面生成一个专用的 WebWorker 时触发。

🌐 Emitted when a dedicated WebWorker is spawned by the page.

WorkerDestroyed

"workerdestroyed"

当页面销毁专用的 WebWorker 时触发。

🌐 Emitted when a dedicated WebWorker is destroyed by the page.