Skip to content

Commit

Permalink
feat: Fallback to custom protocol (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Nov 10, 2021
1 parent 1115c2e commit 00e7a46
Show file tree
Hide file tree
Showing 95 changed files with 1,276 additions and 427 deletions.
9 changes: 3 additions & 6 deletions examples/electron-forge-webpack/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"runtime": {
"name": "Electron",
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///.webpack/renderer/main_window/index.html"
}
},
"release": "electron-forge-webpack@1.0.0",
Expand Down Expand Up @@ -122,7 +118,7 @@
{
"timestamp": 0,
"category": "electron",
"message": "WebContents[1].dom-ready",
"message": "renderer.dom-ready",
"type": "ui"
}
],
Expand All @@ -132,7 +128,8 @@
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event.process": "renderer",
"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: 2 additions & 5 deletions examples/electron-forge/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"runtime": {
"name": "Electron",
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///src/index.html"
}
},
"release": "electron-forge@1.0.0",
Expand Down Expand Up @@ -115,7 +111,7 @@
{
"timestamp": 0,
"category": "electron",
"message": "WebContents[1].dom-ready",
"message": "renderer.dom-ready",
"type": "ui"
}
],
Expand All @@ -125,6 +121,7 @@
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event.process": "renderer",
"event_type": "javascript"
}
}
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 |
136 changes: 136 additions & 0 deletions examples/webpack-context-isolation-preload/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"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}}"
}
},
"release": "webpack-context-isolation-preload@1.0.0",
"environment": "development",
"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": "renderer.dom-ready",
"type": "ui"
}
],
"request": {
"url": "app:///dist/index.html"
},
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event.process": "renderer",
"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()],
},
];
3 changes: 3 additions & 0 deletions examples/webpack-context-isolation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
| Build Command | yarn && yarn build |
| Run Condition | supportsContextIsolation |
| Timeout | 120s |

This test also has a strict Content-Security-Policy to demonstrate that the custom protocol is supported in these
circumstances
9 changes: 3 additions & 6 deletions examples/webpack-context-isolation/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"runtime": {
"name": "Electron",
"version": "{{version}}"
},
"electron": {
"crashed_process": "WebContents[1]",
"crashed_url": "app:///dist/index.html"
}
},
"release": "webpack-context-isolation@1.0.0",
Expand Down Expand Up @@ -123,7 +119,7 @@
{
"timestamp": 0,
"category": "electron",
"message": "WebContents[1].dom-ready",
"message": "renderer.dom-ready",
"type": "ui"
}
],
Expand All @@ -133,7 +129,8 @@
"tags": {
"event.environment": "javascript",
"event.origin": "electron",
"event.process": "renderer",
"event_type": "javascript"
}
}
}
}
5 changes: 3 additions & 2 deletions examples/webpack-context-isolation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"html-webpack-plugin": "^5.3.2",
"webpack": "^5.48.0",
"webpack-cli": "^4.7.2",
"warnings-to-errors-webpack-plugin": "^2.0.1"
"warnings-to-errors-webpack-plugin": "^2.0.1",
"csp-html-webpack-plugin": "^5.1.0"
},
"dependencies": {
"@sentry/electron": "3.0.0"
}
}
}
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
Loading

0 comments on commit 00e7a46

Please sign in to comment.