electron/spec/fixtures/apps/crash/main.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.9 KiB
JavaScript
Raw Normal View History

const { app, BrowserWindow, crashReporter } = require('electron');
const path = require('path');
const childProcess = require('child_process');
app.setVersion('0.1.0');
const url = app.commandLine.getSwitchValue('crash-reporter-url');
const uploadToServer = !app.commandLine.hasSwitch('no-upload');
const setExtraParameters = app.commandLine.hasSwitch('set-extra-parameters-in-renderer');
const addGlobalParam = app.commandLine.getSwitchValue('add-global-param')?.split(':');
crashReporter.start({
productName: 'Zombies',
companyName: 'Umbrella Corporation',
compress: false,
uploadToServer,
submitURL: url,
ignoreSystemCrashHandler: true,
extra: {
mainProcessSpecific: 'mps'
},
globalExtra: addGlobalParam[0] ? { [addGlobalParam[0]]: addGlobalParam[1] } : {}
});
app.whenReady().then(() => {
const crashType = app.commandLine.getSwitchValue('crash-type');
if (crashType === 'main') {
process.crash();
} else if (crashType === 'renderer') {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank');
if (setExtraParameters) {
w.webContents.executeJavaScript(`
require('electron').crashReporter.addExtraParameter('rendererSpecific', 'rs');
require('electron').crashReporter.addExtraParameter('addedThenRemoved', 'to-be-removed');
require('electron').crashReporter.removeExtraParameter('addedThenRemoved');
`);
}
w.webContents.executeJavaScript('process.crash()');
w.webContents.on('render-process-gone', () => process.exit(0));
} else if (crashType === 'sandboxed-renderer') {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload: path.resolve(__dirname, 'sandbox-preload.js'),
contextIsolation: false
}
});
w.loadURL(`about:blank?set_extra=${setExtraParameters ? 1 : 0}`);
w.webContents.on('render-process-gone', () => process.exit(0));
} else if (crashType === 'node') {
const crashPath = path.join(__dirname, 'node-crash.js');
chore: bump chromium to 108.0.5355.0 (main) (#35900) * chore: bump chromium in DEPS to 108.0.5339.0 * chore: bump chromium in DEPS to 108.0.5341.0 * chore: sync patch to unrelated upstream code shear patches/chromium/network_service_allow_remote_certificate_verification_logic.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/printing.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/chore_add_electron_deps_to_gitignores.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3906023 * chore: refresh patches - `e patches all` * chore: remove unused parameter from WillCreateURLLoaderRequestInterceptors Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3932218 * perf: avoid unique pointer round trip Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3913938 * refactor: Simplify entropy provider management. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3901211 * fixup! perf: avoid unique pointer round trip * fixup! perf: avoid unique pointer round trip * refactor: update typeof FileSelectHelper::select_file_dialog_ Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3930092 * fixup! fixup! perf: avoid unique pointer round trip * chore: bump chromium in DEPS to 108.0.5343.0 * chore: update patches * chore: bump chromium in DEPS to 108.0.5345.0 * chore: bump chromium in DEPS to 108.0.5347.0 * chore: bump chromium in DEPS to 108.0.5349.0 * chore: bump chromium in DEPS to 108.0.5351.0 * chore: bump chromium in DEPS to 108.0.5353.0 * chore: bump chromium in DEPS to 108.0.5355.0 * chore: update patches * Refactor display::win::DisplayInfo to display::win::internal::DisplayInfo Refs https://chromium-review.googlesource.com/c/chromium/src/+/3929014 * Update proxy resolution to use NAK - Part 2 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3934016 * Disable PreconnectManager when the user disabled preloading. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3928470 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3937183 * chore: update patches * chore: update sysroot * linux: Remove breakpad integration Refs https://chromium-review.googlesource.com/c/chromium/src/+/3764621 * chore: update comments Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-17 14:22:24 +00:00
const child = childProcess.fork(crashPath, { silent: true });
child.on('exit', () => process.exit(0));
} else if (crashType === 'node-fork') {
const scriptPath = path.join(__dirname, 'fork.js');
const child = childProcess.fork(scriptPath, { silent: true });
child.on('exit', () => process.exit(0));
} else if (crashType === 'node-extra-args') {
let exitcode = -1;
const crashPath = path.join(__dirname, 'node-extra-args.js');
const child = childProcess.fork(crashPath, ['--enable-logging'], { silent: true });
child.send('message');
child.on('message', (forkedArgs) => {
if (JSON.stringify(forkedArgs) !== JSON.stringify(child.spawnargs)) { exitcode = 1; } else { exitcode = 0; }
process.exit(exitcode);
});
} else {
console.error(`Unrecognized crash type: '${crashType}'`);
process.exit(1);
}
});
setTimeout(() => app.exit(), 30000);