Skip to main content

netLog

记录会话的网络事件。

进程:主进程

🌐 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.

note

除非另有说明,所有方法只能在 app 模块发出 ready 事件之后使用。

方法

🌐 Methods

netLog.startLogging(path[, options])

  • path 字符串 - 用于记录网络日志的文件路径。
  • options 对象(可选)
    • captureMode 字符串(可选)- 应该捕获哪种类型的数据。默认情况下,只会捕获关于请求的元数据。将其设置为 includeSensitive 将包括 cookies 和认证数据。将其设置为 everything 将包括通过套接字传输的所有字节。可以是 defaultincludeSensitiveeverything
    • maxFileSize 数字(可选)- 当日志超过此大小时,记录将自动停止。默认值为无限制。

返回 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.