Skip to content

Commit

Permalink
Fallback to protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Nov 5, 2021
1 parent 189273b commit ea4333b
Show file tree
Hide file tree
Showing 56 changed files with 744 additions and 335 deletions.
5 changes: 2 additions & 3 deletions examples/electron-forge-webpack/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///.webpack/renderer/main_window/index.html"
"crashed_process": "renderer"
}
},
"release": "electron-forge-webpack@1.0.0",
Expand Down Expand Up @@ -135,4 +134,4 @@
"event_type": "javascript"
}
}
}
}
5 changes: 1 addition & 4 deletions examples/electron-forge-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
{
"html": "./src/index.html",
"js": "./src/renderer.js",
"name": "main_window",
"preload": {
"js": "@sentry/electron/preload"
}
"name": "main_window"
}
]
}
Expand Down
2 changes: 0 additions & 2 deletions examples/electron-forge-webpack/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const createWindow = () => {
const mainWindow = new BrowserWindow({
show: false,
webPreferences: {
// eslint-disable-next-line no-undef
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
nodeIntegration: false,
contextIsolation: true,
sandbox: true,
Expand Down
7 changes: 7 additions & 0 deletions examples/webpack-context-isolation-preload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Webpack 5 app with contextIsolation and sandbox with preload

| Setting | Value |
| ------------- | ------------------------ |
| Build Command | yarn && yarn build |
| Run Condition | supportsContextIsolation |
| Timeout | 120s |
139 changes: 139 additions & 0 deletions examples/webpack-context-isolation-preload/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"method": "envelope",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"appId": "277345",
"dumpFile": false,
"data": {
"sdk": {
"name": "sentry.javascript.electron",
"packages": [
{
"name": "npm:@sentry/electron",
"version": "{{version}}"
}
],
"version": "{{version}}"
},
"contexts": {
"app": {
"app_name": "webpack-context-isolation-preload",
"app_version": "1.0.0"
},
"browser": {
"name": "Chrome"
},
"chrome": {
"name": "Chrome",
"type": "runtime",
"version": "{{version}}"
},
"device": {
"arch": "{{arch}}",
"family": "Desktop"
},
"node": {
"name": "Node",
"type": "runtime",
"version": "{{version}}"
},
"os": {
"name": "{{platform}}",
"version": "{{version}}"
},
"runtime": {
"name": "Electron",
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///dist/index.html"
}
},
"release": "webpack-context-isolation-preload@1.0.0",
"environment": "production",
"user": {
"ip_address": "{{auto}}",
"id": "abc-123"
},
"exception": {
"values": [
{
"type": "Error",
"value": "Some renderer error",
"stacktrace": {
"frames": [
{
"colno": 0,
"filename": "app:///dist/renderer.js",
"function": "{{function}}",
"in_app": true,
"lineno": 0
},
{
"colno": 0,
"filename": "app:///dist/renderer.js",
"function": "{{function}}",
"in_app": true,
"lineno": 0
}
]
},
"mechanism": {
"handled": true,
"type": "generic"
}
}
]
},
"level": "error",
"event_id": "{{id}}",
"platform": "javascript",
"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": "WebContents[1].dom-ready",
"type": "ui"
}
],
"request": {
"url": "app:///dist/index.html"
},
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event_type": "javascript"
}
}
}
18 changes: 18 additions & 0 deletions examples/webpack-context-isolation-preload/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "webpack-context-isolation-preload",
"version": "1.0.0",
"scripts": {
"start": "electron .",
"build": "webpack"
},
"main": "dist/main.js",
"devDependencies": {
"html-webpack-plugin": "^5.3.2",
"webpack": "^5.48.0",
"webpack-cli": "^4.7.2",
"warnings-to-errors-webpack-plugin": "^2.0.1"
},
"dependencies": {
"@sentry/electron": "3.0.0"
}
}
33 changes: 33 additions & 0 deletions examples/webpack-context-isolation-preload/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true,
sandbox: true,
},
});

window.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}),
);
});
14 changes: 14 additions & 0 deletions examples/webpack-context-isolation-preload/src/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eslint-disable-next-line import/no-unresolved
import { init, configureScope } from '@sentry/electron';

init({
debug: true,
});

configureScope((scope) => {
scope.setUser({ id: 'abc-123' });
});

setTimeout(() => {
throw new Error('Some renderer error');
}, 500);
33 changes: 33 additions & 0 deletions examples/webpack-context-isolation-preload/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WarningsToErrorsPlugin = require('warnings-to-errors-webpack-plugin');

module.exports = [
{
mode: 'production',
entry: './src/main.js',
target: 'electron-main',
output: {
libraryTarget: 'commonjs2',
filename: 'main.js',
},
plugins: [new WarningsToErrorsPlugin()],
},
{
mode: 'production',
entry: '@sentry/electron/preload',
target: 'electron-preload',
output: {
filename: 'preload.js',
},
plugins: [new WarningsToErrorsPlugin()],
},
{
mode: 'production',
entry: './src/renderer.js',
target: 'web',
output: {
filename: 'renderer.js',
},
plugins: [new HtmlWebpackPlugin(), new WarningsToErrorsPlugin()],
},
];
5 changes: 2 additions & 3 deletions examples/webpack-context-isolation/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///dist/index.html"
"crashed_process": "renderer"
}
},
"release": "webpack-context-isolation@1.0.0",
Expand Down Expand Up @@ -136,4 +135,4 @@
"event_type": "javascript"
}
}
}
}
1 change: 0 additions & 1 deletion examples/webpack-context-isolation/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ app.on('ready', () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true,
sandbox: true,
Expand Down
9 changes: 0 additions & 9 deletions examples/webpack-context-isolation/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ module.exports = [
},
plugins: [new WarningsToErrorsPlugin()],
},
{
mode: 'production',
entry: '@sentry/electron/preload',
target: 'electron-preload',
output: {
filename: 'preload.js',
},
plugins: [new WarningsToErrorsPlugin()],
},
{
mode: 'production',
entry: './src/renderer.js',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@types/koa-bodyparser": "^4.3.0",
"@types/mocha": "^9.0.0",
"busboy": "^0.3.1",
"chai": "^4.1.2",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"cross-env": "^7.0.3",
Expand Down
1 change: 1 addition & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './ipc';
export * from './normalize';
export * from './walk';
export * from './merge';
export * from './mode';
14 changes: 4 additions & 10 deletions src/common/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { Event } from '@sentry/types';
export const PROTOCOL_SCHEME = 'sentry-ipc';

export enum IPC {
export enum IPCChannel {
/** IPC to check main process is listening */
PING = 'sentry-electron.ping',
/** IPC to send a captured event to Sentry. */
EVENT = 'sentry-electron.event',
/** IPC to capture scope globally. */
SCOPE = 'sentry-electron.scope',
/** IPC to get Electron scope in renderer */
CONTEXT = 'sentry-electron.context',
}

export interface AppContext {
eventDefaults: Event;
appBasePath: string;
}

export interface IPCInterface {
sendScope: (scope: string) => void;
sendEvent: (event: string) => void;
getContext: (callback: (context: string) => void) => void;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/common/mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Ways to communicate between the renderer and main process */
export enum IPCMode {
/** Configures Electron IPC to receive messages from renderers */
Classic = 1,
/** Configures Electron protocol module to receive messages from renderers */
Protocol = 2,
/**
* Configures both methods for best compatibility.
*
* Renderers favour IPC but fall back to protocol if IPC has not
* been configured in a preload script
*/
Both = 3,
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface ElectronOptions extends ElectronMainOptions, BrowserOptions {
//
}

export { IPCMode } from './common';

/**
* The Sentry Electron SDK Client.
*
Expand Down
Loading

0 comments on commit ea4333b

Please sign in to comment.