You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
When sending a message to the plugin from the WebView using window.postMessage a Promise is returned (as documented). It works great when the event handler on the plugin side finishes as expected, but when an error is thrown on the plugin side the postMessage received error seems to be an empty object.
I tried passing browserWindow.webContents.on with event handlers that are both synchronous and asynchronous functions and both behave that way.
Is that the actual behavior or am I missing something? If it is, it would be great to get the full error information on the WebView side.
Thanks,
Barak
The text was updated successfully, but these errors were encountered:
Baraksi
changed the title
Handling errors when sending a message to the plugin from the WebView
Handling received errors when sending a message to the plugin from the WebView
Nov 27, 2020
Hello @Baraksi,
there is kinda a workaround for this. If an error occurs, you can send the error back to the webview:
// Sent from the webview to the plugin.// But it will get rejected, because some error occuredwindow.postMessage('faultyCall',{helloMessage: "Hello World!",})
// Event received by pluginbrowserWindow.webContents.on('faultyCall',function(event){const{ helloMessage }=event;// If an error occurs during execution, the Promise from the webview simply gets rejected.// This is bad, because we would never know WHY it got rejected. So we catch, log and throw again.try{doSomethingThatRaisesAnError(helloMessage);}catch(error){// Log error to Sketch, so you know what went wrongconsole.error(error);// Send error message back to webview and handle error separately// or straight up call a function with error as parametersendToWebview("unique.id",`window.error = ${JSON.stringify(error.toString())};`);// Continue throwing error, so Promise in webview will get rejected throwerror;}});
Hey,
When sending a message to the plugin from the WebView using window.postMessage a Promise is returned (as documented). It works great when the event handler on the plugin side finishes as expected, but when an error is thrown on the plugin side the postMessage received error seems to be an empty object.
I tried passing browserWindow.webContents.on with event handlers that are both synchronous and asynchronous functions and both behave that way.
Is that the actual behavior or am I missing something? If it is, it would be great to get the full error information on the WebView side.
Thanks,
Barak
The text was updated successfully, but these errors were encountered: