충돌 보고
충돌 보고를 설정하여 충돌 로그를 자동으로 수집하고 전송하고, 애플리케이션의 중요한 문제를 식별하고 해결합니다.
충돌 보고은(는) CoddyKit의 무료 Electron Desktop App Development 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Electron Desktop App Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Electron Desktop App Development 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Crash Reports Matter
Ever had an app suddenly close without warning? That's a crash! Crash reporting is a vital tool that automatically collects information about these unexpected errors.
This data helps developers understand what went wrong, fix bugs, and improve the stability and reliability of their applications. It's like a black box for your app!
Electron's Built-in Tool
Electron comes with a powerful, built-in crashReporter module. This module monitors your application for crashes and, when one occurs, sends a report to a designated server.
It works for both the main process (Node.js) and renderer processes (web content), ensuring comprehensive coverage.
Starting the Crash Reporter
To enable crash reporting, you need to initialize it in your main process as early as possible, typically before any windows are created. Here's how:
const { app, crashReporter, BrowserWindow } = require('electron');
// IMPORTANT: Call crashReporter.start() as early as possible
crashReporter.start({
productName: 'MyElectronApp',
companyName: 'MyCompany',
submitURL: 'http://localhost:1127/post', // Replace with your actual crash server URL
uploadToServer: true,
});
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
mainWindow.loadFile('index.html');
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
// In macOS, usually re-create a window in the app when the dock icon is clicked
// For this example, we'll just ensure the app doesn't quit on macOS by default
}
});Configuring Your Reports
When you call crashReporter.start(), you provide several important options:
productName: The name of your application.companyName: Your company's name.submitURL: This is the most crucial! It's the URL of the server endpoint that will receive your crash reports.uploadToServer: Set totrueto automatically send reports.
Without a valid submitURL pointing to a server that can accept these reports, they won't be sent anywhere!
Crashing the Main Process
You can intentionally crash the main process to test your setup. The process.crash() method will terminate the process immediately, triggering the crash reporter.
Remember, this is for testing! In a real app, crashes are usually unexpected. The crash reporter will send a report even if the app completely freezes.
const { app, crashReporter, BrowserWindow } = require('electron');
crashReporter.start({
productName: 'MyElectronApp',
companyName: 'MyCompany',
submitURL: 'http://localhost:1127/post',
uploadToServer: true,
});
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
mainWindow.loadFile('index.html');
// Simulate a crash after 5 seconds for testing
setTimeout(() => {
console.log('Simulating main process crash...');
process.crash(); // This will crash the app!
}, 5000);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
// In macOS, usually re-create a window in the app when the dock icon is clicked
}
});Handling Renderer Crashes
The crashReporter also monitors your renderer processes. If a renderer process crashes (e.g., due to a JavaScript error or a native module issue in the web content), Electron will detect it.
The main process will then attempt to send a crash report, similar to a main process crash. You can listen for the 'render-process-gone' event on a BrowserWindow to detect renderer crashes.
Attaching Extra Context
Crash reports are more useful with context! You can add custom key-value pairs to your crash reports using crashReporter.addExtraParameter().
This allows you to include information like the user's ID, current application state, or specific feature flags, which can be invaluable for debugging.
const { app, crashReporter, BrowserWindow } = require('electron');
crashReporter.start({
productName: 'MyElectronApp',
companyName: 'MyCompany',
submitURL: 'http://localhost:1127/post',
uploadToServer: true,
});
// Add extra parameters BEFORE a crash occurs
crashReporter.addExtraParameter('userId', 'user123');
crashReporter.addExtraParameter('appState', 'editing_document');
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
mainWindow.loadFile('index.html');
// Simulate a crash for demonstration
setTimeout(() => {
console.log('Simulating crash with extra data...');
process.crash();
}, 5000);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
// In macOS, usually re-create a window in the app when the dock icon is clicked
}
});Receiving Crash Reports
Once Electron sends a crash report, it needs a server to receive it. This server typically stores the report and might process it further, perhaps even symbolicate the stack traces.
You can set up your own basic HTTP endpoint or use a specialized crash reporting service like Sentry, Bugsnag, or Crashlytics, which provide robust dashboards and analytics.
Best Practices & Privacy
When implementing crash reporting, keep these in mind:
- Privacy: Be careful not to send sensitive user data in crash reports.
- Consent: Inform users that crash reports are being sent and give them an option to opt-out if possible.
- Testing: Always test your crash reporting setup thoroughly to ensure reports are being sent and received correctly.
- Symbolication: For native crashes, you'll need to symbolicate the reports to get human-readable stack traces.
Crash Reporting Quiz
Test your understanding of Electron's crash reporting.
Summary & What's Next
In this lesson, you learned how to set up crash reporting in your Electron application. We covered initializing the crashReporter, configuring its options, simulating crashes, and adding extra data to reports.
Implementing crash reporting is a crucial step towards building robust and reliable desktop applications. Next, consider exploring specific crash reporting services to manage and analyze your collected data more effectively!
자주 묻는 질문
“충돌 보고” 강의는 무료인가요?
네 — “충돌 보고” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Electron Desktop App Development 강의 전체를 잠금 해제할 수 있습니다. Electron Desktop App Development 강의에는 총 4개의 강의가 포함되어 있습니다.
“충돌 보고”에서 뭘 배우나요?
충돌 보고를 설정하여 충돌 로그를 자동으로 수집하고 전송하고, 애플리케이션의 중요한 문제를 식별하고 해결합니다. 브라우저에서 직접 실행하는 실습 코드로 Electron Desktop App Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Electron Desktop App Development을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Electron Desktop App Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“충돌 보고” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Electron Desktop App Development 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Electron Desktop App Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.