Skip to content

Commit

Permalink
fix: Normalize module path in main process
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Jul 13, 2023
1 parent 0fa7104 commit c1c0047
Show file tree
Hide file tree
Showing 13 changed files with 1,954 additions and 71 deletions.
143 changes: 143 additions & 0 deletions examples/webpack-main-process/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"method": "envelope",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"appId": "277345",
"data": {
"sdk": {
"name": "sentry.javascript.electron",
"packages": [
{
"name": "npm:@sentry/electron",
"version": "{{version}}"
}
],
"version": "{{version}}"
},
"contexts": {
"app": {
"app_name": "webpack-main-process",
"app_version": "1.0.0",
"app_start_time": "{{time}}"
},
"browser": {
"name": "Chrome"
},
"chrome": {
"name": "Chrome",
"type": "runtime",
"version": "{{version}}"
},
"device": {
"arch": "{{arch}}",
"family": "Desktop",
"memory_size": 0,
"free_memory": 0,
"processor_count": 0,
"processor_frequency": 0,
"cpu_description": "{{cpu}}",
"screen_resolution":"{{screen}}",
"screen_density": 1,
"language": "{{language}}"
},
"node": {
"name": "Node",
"type": "runtime",
"version": "{{version}}"
},
"os": {
"name": "{{platform}}",
"version": "{{version}}"
},
"runtime": {
"name": "Electron",
"version": "{{version}}"
}
},
"release": "[email protected]",
"environment": "development",
"user": {
"ip_address": "{{auto}}",
"id": "abc-123"
},
"debug_meta": {
"images": [
{
"code_file": "app:///dist/main.js",
"type": "sourcemap"
}
]
},
"exception": {
"values": [
{
"type": "Error",
"value": "Some main error",
"stacktrace": {
"frames": [
{
"colno": 0,
"filename": "app:///dist/main.js",
"function": "{{function}}",
"in_app": true,
"lineno": 0,
"module": "main"
}
]
},
"mechanism": {
"handled": true,
"type": "generic"
}
}
]
},
"level": "fatal",
"event_id": "{{id}}",
"platform": "node",
"timestamp": 0,
"breadcrumbs": [
{
"timestamp": 0,
"category": "electron",
"message": "app.will-finish-launching",
"type": "ui"
},
{
"timestamp": 0,
"category": "electron",
"message": "app.ready",
"type": "ui"
},
{
"timestamp": 0,
"category": "electron",
"message": "app.session-created",
"type": "ui"
},
{
"timestamp": 0,
"category": "electron",
"message": "app.web-contents-created",
"type": "ui"
},
{
"timestamp": 0,
"category": "electron",
"message": "app.browser-window-created",
"type": "ui"
},
{
"timestamp": 0,
"category": "electron",
"message": "renderer.dom-ready",
"type": "ui"
}
],
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event.process": "browser",
"event_type": "javascript"
}
}
}
20 changes: 20 additions & 0 deletions examples/webpack-main-process/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "webpack-main-process",
"version": "1.0.0",
"scripts": {
"start": "electron .",
"build": "webpack"
},
"main": "dist/main.js",
"devDependencies": {
"@sentry/webpack-plugin": "^2.2.0",
"csp-html-webpack-plugin": "^5.1.0",
"html-webpack-plugin": "^5.3.2",
"warnings-to-errors-webpack-plugin": "^2.0.1",
"webpack": "^5.48.0",
"webpack-cli": "^4.7.2"
},
"dependencies": {
"@sentry/electron": "3.0.0"
}
}
4 changes: 4 additions & 0 deletions examples/webpack-main-process/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: Webpack app with error in main process
command: yarn && yarn build
condition: supportsContextIsolation && supportsSandbox
timeout: 120
36 changes: 36 additions & 0 deletions examples/webpack-main-process/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as path from 'path';
import * as url from 'url';

import { app, BrowserWindow } from 'electron';
// eslint-disable-next-line import/no-unresolved
import { init } from '@sentry/electron';

init({
dsn: '__DSN__',
debug: true,
autoSessionTracking: false,
onFatalError: () => {},
});

app.on('ready', () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
sandbox: true,
},
});

window.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}),
);

setTimeout(() => {
throw new Error('Some main error');
}, 500);
});
10 changes: 10 additions & 0 deletions examples/webpack-main-process/src/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line import/no-unresolved
import { init, configureScope } from '@sentry/electron';

init({
debug: true,
});

configureScope((scope) => {
scope.setUser({ id: 'abc-123' });
});
51 changes: 51 additions & 0 deletions examples/webpack-main-process/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CspHtmlWebpackPlugin = require('csp-html-webpack-plugin');
const WarningsToErrorsPlugin = require('warnings-to-errors-webpack-plugin');
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');

const sentryWebpackPluginOptions = {
authToken: 'some invalid auth token',
org: 'some invalid org',
project: 'some invalid project',
telemetry: false,
sourcemaps: {
assets: [], // no assets to upload - we just care about injecting debug IDs
},
release: {
inject: false,
},
errorHandler() {
// do nothing on errors :)
// They will happen because of the invalid auth token
},
};

module.exports = [
{
mode: 'production',
entry: './src/main.js',
target: 'electron-main',
output: {
libraryTarget: 'commonjs2',
filename: 'main.js',
},
plugins: [new WarningsToErrorsPlugin(), sentryWebpackPlugin(sentryWebpackPluginOptions)],
},
{
mode: 'production',
entry: './src/renderer.js',
target: 'web',
output: {
filename: 'renderer.js',
},
plugins: [
new HtmlWebpackPlugin(),
new WarningsToErrorsPlugin(),
new CspHtmlWebpackPlugin({
'default-src': "'self'",
'script-src': "'self'",
}),
sentryWebpackPlugin(sentryWebpackPluginOptions),
],
},
];
Loading

0 comments on commit c1c0047

Please sign in to comment.