-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(profiling) Fix electron crash (#14216)
This PR fixes the electron crash observed in #13978 I am not entirely sure as to why this causes a sigabrt, so I am working around the issue (obtaining a coredump out of electron did not seem trivial and my knowledge around electron isn't very extensive). The v8 options class and the constants are exposed correctly, I ruled that out, however the crash still seems to happen when they are used in this specific signature. In order to have this running with electron, users will require to use the electron/rebuild package, which is the recommended approach by electron that rebuilds native node addons by providing the correct abi headers for the electron version the user is running. For now, we wont provide any prebuilt binaries and instead rely on the fallback mechanism to load the correct module. I will reevaluate this if it causes issues with bundling and look to add proper runtime electron detection.
- Loading branch information
Showing
7 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/node-profiling/__tests__/electron.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const process = require('process'); | ||
const { test, expect, _electron: electron } = require('@playwright/test'); | ||
|
||
test('an h1 contains hello world"', async () => { | ||
const electronApp = await electron.launch({ | ||
args: ['./index.electron.js'], | ||
process: { | ||
env: { | ||
...process.env, | ||
}, | ||
}, | ||
}); | ||
|
||
// Wait for the first BrowserWindow to open | ||
const window = await electronApp.firstWindow(); | ||
|
||
// Check for the presence of an h1 element with the text "hello" | ||
const headerElement = await window.$('h1'); | ||
const headerText = await headerElement.textContent(); | ||
expect(headerText).toBe('Hello From Profiled Electron App'); | ||
|
||
// Close the app | ||
await electronApp.close(); | ||
}); |
54 changes: 54 additions & 0 deletions
54
dev-packages/e2e-tests/test-applications/node-profiling/index.electron.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Modules to control application life and create native browser window | ||
const { app, BrowserWindow } = require('electron'); | ||
const Sentry = require('@sentry/electron/main'); | ||
const path = require('node:path'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302', | ||
debug: true, | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
// Hog the cpu for a second | ||
function block() { | ||
const start = Date.now(); | ||
while (start + 1000 > Date.now()) {} | ||
} | ||
|
||
const createWindow = () => { | ||
block(); | ||
// Create the browser window. | ||
const mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
}, | ||
}); | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadFile('index.html'); | ||
block(); | ||
}; | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.whenReady().then(() => { | ||
Sentry.profiler.startProfiler(); | ||
createWindow(); | ||
Sentry.profiler.stopProfiler(); | ||
|
||
app.on('activate', () => { | ||
// On macOS it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
}); | ||
}); | ||
|
||
// Quit when all windows are closed, except on macOS. There, it's common | ||
// for applications and their menu bar to stay active until the user quits | ||
// explicitly with Cmd + Q. | ||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') app.quit(); | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-profiling/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>Hello From Profiled Electron App</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters