Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/use-tracing-…
Browse files Browse the repository at this point in the history
…client-options
  • Loading branch information
timfish committed Jul 25, 2023
2 parents 6e595b0 + 7582ded commit e3ff977
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 81 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@
"e2e": "cross-env TS_NODE_PROJECT=tsconfig.json xvfb-maybe mocha --require ts-node/register/transpile-only --retries 3 ./test/e2e/*.ts"
},
"dependencies": {
"@sentry/browser": "7.58.0",
"@sentry/core": "7.58.0",
"@sentry/node": "7.58.0",
"@sentry/types": "7.58.0",
"@sentry/utils": "7.58.0",
"@sentry/browser": "7.60.0",
"@sentry/core": "7.60.0",
"@sentry/node": "7.60.0",
"@sentry/types": "7.60.0",
"@sentry/utils": "7.60.0",
"deepmerge": "4.3.0",
"lru_map": "^0.3.3",
"tslib": "^2.5.0"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "7.58.0",
"@sentry-internal/typescript": "7.58.0",
"@sentry-internal/eslint-config-sdk": "7.60.0",
"@sentry-internal/typescript": "7.60.0",
"@types/busboy": "^0.2.3",
"@types/chai": "^4.2.10",
"@types/chai-as-promised": "^7.1.5",
Expand Down Expand Up @@ -107,4 +107,4 @@
"node": "18.12.1",
"yarn": "1.22.19"
}
}
}
44 changes: 44 additions & 0 deletions src/main/electron-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,47 @@ export function capturePage(window: BrowserWindow): Promise<NativeImage> {

return window.capturePage();
}

/**
* Electron >= 25 support `protocol.handle`
*/
function supportsProtocolHandle(): boolean {
return version.major >= 25;
}

interface InternalRequest {
url: string;
body?: Buffer;
}

/**
* Registers a custom protocol to receive events from the renderer
*
* Uses `protocol.handle` if available, otherwise falls back to `protocol.registerStringProtocol`
*/
export function registerProtocol(
protocol: Electron.Protocol,
scheme: string,
callback: (request: InternalRequest) => void,
): void {
if (supportsProtocolHandle()) {
protocol.handle(scheme, async (request) => {
callback({
url: request.url,
body: Buffer.from(await request.arrayBuffer()),
});

return new Response('');
});
} else {
// eslint-disable-next-line deprecation/deprecation
protocol.registerStringProtocol(scheme, (request, complete) => {
callback({
url: request.url,
body: request.uploadData?.[0]?.bytes,
});

complete('');
});
}
}
9 changes: 3 additions & 6 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { app, ipcMain, protocol, WebContents } from 'electron';
import { TextDecoder, TextEncoder } from 'util';

import { IPCChannel, IPCMode, mergeEvents, normalizeUrlsInReplayEnvelope, PROTOCOL_SCHEME } from '../common';
import { supportsFullProtocol, whenAppReady } from './electron-normalize';
import { registerProtocol, supportsFullProtocol, whenAppReady } from './electron-normalize';
import { ElectronMainOptionsInternal } from './sdk';

function captureEventFromRenderer(
Expand Down Expand Up @@ -138,9 +138,8 @@ function configureProtocol(options: ElectronMainOptionsInternal): void {
whenAppReady
.then(() => {
for (const sesh of options.getSessions()) {
// eslint-disable-next-line deprecation/deprecation
sesh.protocol.registerStringProtocol(PROTOCOL_SCHEME, (request, callback) => {
const data = request.uploadData?.[0]?.bytes;
registerProtocol(sesh.protocol, PROTOCOL_SCHEME, (request) => {
const data = request.body;

if (request.url.startsWith(`${PROTOCOL_SCHEME}://${IPCChannel.EVENT}`) && data) {
handleEvent(options, data.toString());
Expand All @@ -149,8 +148,6 @@ function configureProtocol(options: ElectronMainOptionsInternal): void {
} else if (request.url.startsWith(`${PROTOCOL_SCHEME}://${IPCChannel.ENVELOPE}`) && data) {
handleEnvelope(options, data);
}

callback('');
});
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const defaultIntegrations = [...defaultBrowserIntegrations, new ScopeToMa
export function init<O extends BrowserOptions>(
options: BrowserOptions & O = {} as BrowserOptions & O,
// This parameter name ensures that TypeScript error messages contain a hint for fixing SDK version mismatches
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v7_58_0: O) => void = browserInit,
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v7_60_0: O) => void = browserInit,
): void {
ensureProcess('renderer');

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["2.0.18","3.1.13","4.2.12","5.0.13","6.1.12","7.3.3","8.5.5","9.4.4","10.4.7","11.5.0","12.2.3","13.6.9","14.2.9","15.5.7","16.2.8","17.4.11","18.3.15","19.1.9","20.3.12","21.4.4","22.3.16","23.3.10","24.6.2","25.2.0"]
["2.0.18","3.1.13","4.2.12","5.0.13","6.1.12","7.3.3","8.5.5","9.4.4","10.4.7","11.5.0","12.2.3","13.6.9","14.2.9","15.5.7","16.2.8","17.4.11","18.3.15","19.1.9","20.3.12","21.4.4","22.3.17","23.3.10","24.6.3","25.3.0"]
Loading

0 comments on commit e3ff977

Please sign in to comment.