Skip to content

Instantly share code, notes, and snippets.

@deepak1556
Last active November 26, 2019 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak1556/f9ce7fd4d695361f1568c787affa3795 to your computer and use it in GitHub Desktop.
Save deepak1556/f9ce7fd4d695361f1568c787affa3795 to your computer and use it in GitHub Desktop.
Debugging Async/Await crash with electron
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
<script>
class Foo {
constructor() {
document.body.addEventListener('click', () => {
this.foo();
});
}
async foo() {
document.title = "test"; // Triggers `page-title-updated` event in main process which queues a ipc for our POC
await this.foo2(); // set breakpoint in this line
await this.foo2();
}
async foo2() {
return Promise.resolve();
}
}
new Foo();
</script>
</html>
const {app, BrowserWindow} = require('electron')
const path = require('path')
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.webContents.on('page-title-updated', () => {
// This will trigger the Microtasks after exiting the CallbackScope
// in InvokeIpcCallback under electron_api_service_impl.cc
// which causes the pending promises to fulfill when debug is paused
// and crashes in v8 with EXC_BAD_ACCESS
mainWindow.webContents.send('test')
})
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
if (mainWindow === null) createWindow()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment