Skip to main content

netLog

记录会话的网络事件。

¥Logging network events for a session.

进程:主进程

¥Process: Main

const { app, netLog } = require('electron')

app.whenReady().then(async () => {
await netLog.startLogging('/path/to/net-log')
// After some network events
const path = await netLog.stopLogging()
console.log('Net-logs written to', path)
})

请参阅 --log-net-log 以在应用的整个生命周期中记录网络事件。

¥See --log-net-log to log network events throughout the app's lifecycle.

注意:除非指定,否则所有方法只能在 app 模块的 ready 事件发出后使用。

¥Note: All methods unless specified can only be used after the ready event of the app module gets emitted.

方法

¥Methods

netLog.startLogging(path[, options])

  • path 字符串 - 记录网络日志的文件路径。

    ¥path string - File path to record network logs.

  • options 对象(可选)

    ¥options Object (optional)

    • captureMode 字符串(可选) - 应该捕获什么类型的数据。默认情况下,仅捕获有关请求的元数据。将其设置为 includeSensitive 将包括 cookie 和身份验证数据。将其设置为 everything 将包括套接字上传输的所有字节。可以是 defaultincludeSensitiveeverything

      ¥captureMode string (optional) - What kinds of data should be captured. By default, only metadata about requests will be captured. Setting this to includeSensitive will include cookies and authentication data. Setting it to everything will include all bytes transferred on sockets. Can be default, includeSensitive or everything.

    • maxFileSize 号码(可选) - 当日志增长超过此大小时,日志记录将自动停止。默认为无限制。

      ¥maxFileSize number (optional) - When the log grows beyond this size, logging will automatically stop. Defaults to unlimited.

返回 Promise<void> - 当网络日志开始记录时解决。

¥Returns Promise<void> - resolves when the net log has begun recording.

开始将网络事件记录到 path

¥Starts recording network events to path.

netLog.stopLogging()

返回 Promise<void> - 当网络日志已刷新到磁盘时解决。

¥Returns Promise<void> - resolves when the net log has been flushed to disk.

停止记录网络事件。如果不调用,网络日志记录将在应用退出时自动结束。

¥Stops recording network events. If not called, net logging will automatically end when app quits.

属性

¥Properties

netLog.currentlyLogging 只读

¥netLog.currentlyLogging Readonly

boolean 属性,指示当前是否正在记录网络日志。

¥A boolean property that indicates whether network logs are currently being recorded.