feat: enhance unresponsive renderer handling and crash reporting (#6995)

* feat: enhance unresponsive renderer handling and crash reporting

* Added support for collecting JavaScript call stacks from unresponsive renderers.
* Updated the Document Policy in the HTML to include JS call stacks in crash reports.
* Removed legacy unresponsive logging from WindowService.

* feat: improve unresponsive renderer handling and update crash reporting

* Added session web request handling to include Document-Policy for JS call stacks in crash reports.
* Removed legacy Document-Policy meta tag from HTML.
* Enhanced logging for unresponsive renderer call stacks.

* fix: remove unused session import in index.ts

---------

Co-authored-by: beyondkmp <beyondkmkp@gmail.com>
This commit is contained in:
beyondkmp 2025-06-09 19:50:05 +08:00 committed by GitHub
parent ac7d4cb4fa
commit b951d89c6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View File

@ -34,6 +34,26 @@ if (isWin) {
app.commandLine.appendSwitch('wm-window-animations-disabled')
}
// Enable features for unresponsive renderer js call stacks
app.commandLine.appendSwitch('enable-features', 'DocumentPolicyIncludeJSCallStacksInCrashReports')
app.on('web-contents-created', (_, webContents) => {
webContents.session.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Document-Policy': ['include-js-call-stacks-in-crash-reports']
}
})
})
webContents.on('unresponsive', async () => {
// Interrupt execution and collect call stack from unresponsive renderer
Logger.error('Renderer unresponsive start')
const callStack = await webContents.mainFrame.collectJavaScriptCallStack()
Logger.error('Renderer unresponsive js call stack\n', callStack)
})
})
// in production mode, handle uncaught exception and unhandled rejection globally
if (!isDev) {
// handle uncaught exception

View File

@ -116,12 +116,6 @@ export class WindowService {
app.exit(1)
}
})
mainWindow.webContents.on('unresponsive', () => {
// 在升级到electron 34后可以获取具体js stack trace,目前只打个日志监控下
// https://www.electronjs.org/blog/electron-34-0#unresponsive-renderer-javascript-call-stacks
Logger.error('Renderer process unresponsive')
})
}
private setupMaximize(mainWindow: BrowserWindow, isMaximized: boolean) {