Preflight Checklist
Issue Details
When calling functions exposed by contextBridge.exposeInMainWorld, Promises rejected with Error objects or directly thrown Errors (and even caught Errors returned in a wrapper) are not copied as the documentation states – all important information except the message is removed, e.g. Common System Error properties like err.code, err.path etc. are gone. Also, the “Uncaught Error: ” message prefix is not very helpful.
- Electron Version:
- Operating System:
Expected Behavior
Instances of the Error class (or inherited from it) coming from the context bridge should have all properties preserved (except err.stack, obviously) and message left intact to allow meaningful error handling. Structured Clone Algorithm otherwise serializes Error objects correctly.
Actual Behavior
The Error object is stripped of important additional properties and has a confusing message saying it’s uncaught even when caught on both sides of the bridge.
To Reproduce
preload.js
const { contextBridge } = require('electron');
const fs = require('fs');
contextBridge.exposeInMainWorld('myapi', {
request: () => fs.lstatSync('foo')
});
renderer
try {
window.myapi.request();
} catch (e) {
console.dir(e);
}
Preflight Checklist
Issue Details
When calling functions exposed by
contextBridge.exposeInMainWorld, Promises rejected with Error objects or directly thrown Errors (and even caught Errors returned in a wrapper) are not copied as the documentation states – all important information except the message is removed, e.g. Common System Error properties likeerr.code,err.pathetc. are gone. Also, the “Uncaught Error: ” message prefix is not very helpful.Expected Behavior
Instances of the Error class (or inherited from it) coming from the context bridge should have all properties preserved (except
err.stack, obviously) and message left intact to allow meaningful error handling. Structured Clone Algorithm otherwise serializes Error objects correctly.Actual Behavior
The Error object is stripped of important additional properties and has a confusing message saying it’s uncaught even when caught on both sides of the bridge.
To Reproduce
preload.js
renderer