Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 7.1.1

- fix: Preload injection path (#1243)
- fix: Preload `contextIsolation` issues (#1244)

## 7.1.0

Expand Down
3 changes: 2 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function hookupIpc(namespace: string = 'sentry-ipc'): void {
if (contextBridge) {
// This will fail if contextIsolation is not enabled
try {
contextBridge.exposeInMainWorld(ipcUtil.namespace, ipcObject);
// eslint-disable-next-line no-restricted-globals
contextBridge.exposeInMainWorld('__SENTRY_IPC__', window.__SENTRY_IPC__);
} catch (e) {
//
}
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { ElectronRendererOptionsInternal } from './sdk.js';
function getImplementation(ipcKey: string): IPCInterface {
const ipcUtil = ipcChannelUtils(ipcKey);

window.__SENTRY_IPC__ = window.__SENTRY_IPC__ || {};

// Favour IPC if it's been exposed by a preload script
if (window.__SENTRY_IPC__[ipcUtil.namespace]) {
if (window.__SENTRY_IPC__?.[ipcUtil.namespace]) {
return window.__SENTRY_IPC__[ipcUtil.namespace] as IPCInterface;
} else {
debug.log('IPC was not configured in preload script, falling back to custom protocol and fetch');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// eslint-disable-next-line import/no-unresolved
import { init } from '@sentry/electron/main';
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import * as url from 'url';
const { init, IPCMode } = require('@sentry/electron/main');
const { app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');

init({
dsn: '__DSN__',
debug: true,
ipcMode: IPCMode.Classic,
onFatalError: () => {},
});

Expand All @@ -22,13 +23,9 @@ app.on('ready', () => {

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

setTimeout(() => {
throw new Error('Some main error');
}, 2000);
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "webpack-main-process",
"description": "Webpack app with error in main process",
"name": "preload-injection",
"description": "Preload injection",
"version": "1.0.0",
"scripts": {
"start": "electron .",
"build": "webpack"
},
"main": "dist/main.js",
"main": "main.js",
"devDependencies": {
"@sentry/webpack-plugin": "^2.2.0",
"csp-html-webpack-plugin": "^5.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ init({
console.log('renderer logging');

getCurrentScope().setUser({ id: 'abc-123' });

setTimeout(() => {
throw new Error('Some renderer error');
}, 2000);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ electronTestRunner(__dirname, { skipEsmAutoTransform: true, skip: () => process.
await ctx
.expect({
envelope: eventEnvelope({
level: 'fatal',
platform: 'node',
level: 'error',
platform: 'javascript',
debug_meta: {
images: [
{
code_file: 'app:///dist/main.js',
code_file: 'app:///dist/renderer.js',
type: 'sourcemap',
debug_id: UUID_V4_MATCHER,
},
Expand All @@ -20,30 +20,36 @@ electronTestRunner(__dirname, { skipEsmAutoTransform: true, skip: () => process.
values: [
{
type: 'Error',
value: 'Some main error',
value: 'Some renderer error',
stacktrace: {
frames: expect.arrayContaining([
{
colno: expect.any(Number),
filename: 'app:///dist/main.js',
filename: 'app:///dist/renderer.js',
function: expect.any(String),
in_app: true,
lineno: expect.any(Number),
module: 'dist:main',
},
]),
},
mechanism: {
handled: false,
type: 'generic',
type: 'auto.browser.browserapierrors.setTimeout',
},
},
],
},
request: {
headers: {},
url: 'app:///dist/index.html',
},
extra: {
arguments: [],
},
tags: {
'event.environment': 'javascript',
'event.origin': 'electron',
'event.process': 'browser',
'event.process': 'renderer',
},
user: {
id: 'abc-123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,20 @@ const sentryWebpackPluginOptions = {
},
};

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