fix: sqlite wasm in electron production (#3920)

This commit is contained in:
Stephen Zhou 2025-06-13 22:12:07 +08:00 committed by GitHub
parent d6bdcee6a9
commit 65ebf9ef93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 80 additions and 14 deletions

View File

@ -6,6 +6,7 @@ on:
- "**"
paths:
- "apps/desktop/**"
- "packages/**"
- "pnpm-lock.yaml"
- ".github/workflows/build-desktop.yml"
workflow_dispatch:

View File

@ -112,6 +112,21 @@ function bootstrap() {
callback({ cancel: false, requestHeaders: details.requestHeaders })
})
// It's wired, I can not make this work. For request to worker.js, it will apply an incomplete header.
// not-set cross-origin-embedder-policy:
// Maybe this is related to https://github.com/electron/electron/issues/45168
// So I have to use `app.commandLine.appendSwitch("enable-features", "SharedArrayBuffer")`
//
// session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
// callback({
// responseHeaders: {
// ...details.responseHeaders,
// "Cross-Origin-Opener-Policy": "same-origin",
// "Cross-Origin-Embedder-Policy": "require-corp",
// },
// })
// })
mainWindow = createMainWindow()
updateProxy()

View File

@ -27,6 +27,25 @@ if (process.argv.length === 3 && process.argv[2]!.startsWith("follow-dev:")) {
* Mandatory and fast initializers for the app
*/
export function initializeAppStage0() {
app.commandLine.appendSwitch("enable-features", "SharedArrayBuffer")
// https://github.com/getsentry/sentry-electron/issues/661
protocol.registerSchemesAsPrivileged([
{
scheme: "sentry-ipc",
privileges: { bypassCSP: true, corsEnabled: true, supportFetchAPI: true, secure: true },
},
{
scheme: "app",
privileges: {
standard: true,
bypassCSP: true,
supportFetchAPI: true,
secure: true,
},
},
])
initializeSentry()
initializeIpcServices()
}
@ -59,17 +78,6 @@ export const initializeAppStage1 = () => {
registerPushNotifications()
clearCacheCronJob()
checkAndCleanCodeCache()
protocol.registerSchemesAsPrivileged([
{
scheme: "app",
privileges: {
standard: true,
bypassCSP: true,
supportFetchAPI: true,
},
},
])
}
let contextMenuDisposer: () => void

View File

@ -78,7 +78,8 @@
"react-native-sheet-transitions": "patches/react-native-sheet-transitions.patch",
"react-native-screens": "patches/react-native-screens.patch",
"expo-image": "patches/expo-image.patch",
"react-native-ios-utilities": "patches/react-native-ios-utilities.patch"
"react-native-ios-utilities": "patches/react-native-ios-utilities.patch",
"@sentry/electron": "patches/@sentry__electron.patch"
},
"overrides": {
"@electron/node-gyp": "10.2.0-electron.2",

View File

@ -0,0 +1,38 @@
diff --git a/esm/main/ipc.js b/esm/main/ipc.js
index 8edfaf4660734f9120a6d5f5f806688c25a3a026..a692b1c16470b0dbed7c53e1c9aeff8a456f1c5a 100644
--- a/esm/main/ipc.js
+++ b/esm/main/ipc.js
@@ -111,14 +111,6 @@ function configureProtocol(client, options) {
if (app.isReady()) {
throw new Error("Sentry SDK should be initialized before the Electron app 'ready' event is fired");
}
- protocol.registerSchemesAsPrivileged([SENTRY_CUSTOM_SCHEME]);
- // We Proxy this function so that later user calls to registerSchemesAsPrivileged don't overwrite our custom scheme
- // eslint-disable-next-line @typescript-eslint/unbound-method
- protocol.registerSchemesAsPrivileged = new Proxy(protocol.registerSchemesAsPrivileged, {
- apply: (target, __, args) => {
- target([...args[0], SENTRY_CUSTOM_SCHEME]);
- },
- });
const rendererStatusChanged = createRendererAnrStatusHandler(client);
app
.whenReady()
diff --git a/main/ipc.js b/main/ipc.js
index 01fc75bdf031b62195504cc0bf7055ebbf15b641..0519242ba5f391f9f618229044948feefeae1de8 100644
--- a/main/ipc.js
+++ b/main/ipc.js
@@ -111,14 +111,6 @@ function configureProtocol(client, options) {
if (electron.app.isReady()) {
throw new Error("Sentry SDK should be initialized before the Electron app 'ready' event is fired");
}
- electron.protocol.registerSchemesAsPrivileged([SENTRY_CUSTOM_SCHEME]);
- // We Proxy this function so that later user calls to registerSchemesAsPrivileged don't overwrite our custom scheme
- // eslint-disable-next-line @typescript-eslint/unbound-method
- electron.protocol.registerSchemesAsPrivileged = new Proxy(electron.protocol.registerSchemesAsPrivileged, {
- apply: (target, __, args) => {
- target([...args[0], SENTRY_CUSTOM_SCHEME]);
- },
- });
const rendererStatusChanged = rendererAnr.createRendererAnrStatusHandler(client);
electron.app
.whenReady()

View File

@ -30,6 +30,9 @@ patchedDependencies:
'@pengx17/electron-forge-maker-appimage':
hash: 5b5ab1ba36e8c0d7ffee912ebf29c1a18bc101c9c661ceb1bb0bda3deaf4c667
path: patches/@pengx17__electron-forge-maker-appimage.patch
'@sentry/electron':
hash: b5efa039abfa14f7833b762e8a7c1c3ae147fda22954d860ffa3387db9acf8eb
path: patches/@sentry__electron.patch
daisyui@4.12.24:
hash: d393ab1cbfbfcff21dce0796a59c2d8a37e2c6dd634a8ab476cbc67e47b93d9c
path: patches/daisyui@4.12.24.patch
@ -353,7 +356,7 @@ importers:
version: 1.0.1
'@sentry/electron':
specifier: 6.6.0
version: 6.6.0
version: 6.6.0(patch_hash=b5efa039abfa14f7833b762e8a7c1c3ae147fda22954d860ffa3387db9acf8eb)
builder-util-runtime:
specifier: 9.3.1
version: 9.3.1
@ -21443,7 +21446,7 @@ snapshots:
'@sentry/core@9.22.0': {}
'@sentry/electron@6.6.0':
'@sentry/electron@6.6.0(patch_hash=b5efa039abfa14f7833b762e8a7c1c3ae147fda22954d860ffa3387db9acf8eb)':
dependencies:
'@sentry/browser': 9.18.0
'@sentry/core': 9.18.0