I ran into this issue today, and found a hacky solution. I'm using sketch-module-web-view
for my UI, so I bubble events captured by Sentry in the cocoascript layer into the webview so that my instance of Sentry in the webview can send them. It's ugly, and probably won't capture uncaught exceptions, but it'll let you use Sentry.captureException
.
In the plugin, I configure the beforeSend
init option to send it as a message to the webview. This method is usually used for mutating event data before sending it, but in this case, I'm passing the data along and then telling Sentry to stop.
In the plugin file:
// Create a variable where we can store a BrowserWindow instance
let browserWindow
Sentry.init({
// ...other config
beforeSend: event => {
if (browserWindow) {
// Send the contents of the error to the webview
browserWindow.webContents
.executeJavaScript(`captureException(${JSON.stringify(event)})`)
.catch(console.error)
}
// Return null so sentry doesn't continue to try to send from here.
return null
},
})
// Later, in your plugin command
export default function () {
// save the BrowserWindow instance for later use. You should probably clean it up if your plugin unmounts.
browserWindow = new BrowserWindow(options)
}
In the webview:
window.captureException = payload => {
// This assumes you've already init an instance of Sentry
Sentry.getCurrentHub().getClient().sendEvent(payload)
}
I'm leaving out a lot of details, so this isn't exactly plug-n-play but hopefully a discerning and and harried developer will know what to do with this.