electron/lib/common/crash-reporter.js
Nitish Sakhawalkar f98454e5dd fix: use crashpad on Windows (#18483)
* Initial changes to use crashpad for windows

* Remove crashpad patch

* Report error when failed to connect pipe

* Allow crashpad to communicate with named pipe

* Add patch to make crashpad named pipe work

* Windows also needs crashReporter on main process

* Call SetUnhandledExceptionFilter in node process

Node can also use crash reporter.

* Do not treat node process as browser process

* No more need to manually start crash service

* Use base::StringPrintf for better readbility

* Print error when pipe name not available

* Make sure pipe name is updated

Note that the crashpad may be started after renderer process gets
created.

* Fix some tests

* Update node

* Exclude crashpad files on Linux and MAS

* Fix lint warning

* Remove unused checks

* kCrashpadPipeName is only available on Windows

* Fix uploadToServer tests

* Fix extra params tests

* Fix getCrashesDirectory tests

* Run crashReporter tests on CI

* Style fixes

* Update crashreporter docs

* Rename InitBreakpad to Init

* Add comment for process_type_.empty() and UTF16ToASCII to UTF16ToUTF8.

* Update build.gn include crashpad headers

* Address comment https://github.com/electron/electron/pull/18483#discussion_r290887898

* Avoid using api::WebContents

* Put kRunAsNode in atom_constants

* Remove duplicate settings on upload params

* Fix building on macOS

* Update description for crashpad_pid_check.patch
2019-06-13 15:42:21 +09:00

97 lines
2.4 KiB
JavaScript

'use strict'
const binding = process.electronBinding('crash_reporter')
class CrashReporter {
contructor () {
this.productName = null
this.crashesDirectory = null
}
init (options) {
throw new Error('Not implemented')
}
start (options) {
if (options == null) options = {}
const {
productName,
companyName,
extra = {},
ignoreSystemCrashHandler = false,
submitURL,
uploadToServer = true
} = options
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start')
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start')
const ret = this.init({
submitURL,
productName
})
this.productName = ret.productName
this.crashesDirectory = ret.crashesDirectory
if (extra._productName == null) extra._productName = ret.productName
if (extra._companyName == null) extra._companyName = companyName
if (extra._version == null) extra._version = ret.appVersion
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra)
}
getLastCrashReport () {
const reports = this.getUploadedReports()
.sort((a, b) => {
const ats = (a && a.date) ? new Date(a.date).getTime() : 0
const bts = (b && b.date) ? new Date(b.date).getTime() : 0
return bts - ats
})
return (reports.length > 0) ? reports[0] : null
}
getUploadedReports () {
return binding.getUploadedReports(this.getCrashesDirectory())
}
getCrashesDirectory () {
return this.crashesDirectory
}
getProductName () {
return this.productName
}
getUploadToServer () {
if (process.type === 'browser') {
return binding.getUploadToServer()
} else {
throw new Error('getUploadToServer can only be called from the main process')
}
}
setUploadToServer (uploadToServer) {
if (process.type === 'browser') {
return binding.setUploadToServer(uploadToServer)
} else {
throw new Error('setUploadToServer can only be called from the main process')
}
}
addExtraParameter (key, value) {
binding.addExtraParameter(key, value)
}
removeExtraParameter (key) {
binding.removeExtraParameter(key)
}
getParameters () {
return binding.getParameters()
}
}
module.exports = CrashReporter