Description
- Electron version: 1.6.5
- Operating system: OSX
Expected behavior
Possible solutions
-
Set a more useful
filename
in the throwed error on the window object for identify where it happened (usefull) -
The result/promise is never resolved now. Maybe it should get a callback with error argument and reject the promise exactly in this case?
Documentation:
The documentation requires a better overview where/how to catch errors. Additionally some other information to understand the working of the different contexts.
Something like:
Location | Unhandled errors | Available modules*** | Exposed variables**** |
---|---|---|---|
preload.js | ? | ? | ? |
executeJavaScript()* | ? | ? | ? |
page scripts 5) | window error handler** | ? | ? |
*) webContents.executeJavaScript function
**) window.addEventListener('error', function(errorEvent) {})
or window. {}
***) which modules can be imported by using the require
global function
****) In the global context (can be the window object)
5) all scripts which is executed on the page or it resources
Web preferences which alter things:
Web preference | default | How it alter things |
---|---|---|
sandbox | false | describe here... |
contextIsolation | false | describe here... |
nodeIntegration | true | describe here... |
javascript | false | if false then: all javascript execution is prevented |
webSecurity | false | if false then: describe here... |
Actual behavior
If you use executeJavaScript it's difficult to catch the error which occurs in the passed javascript.
In renderer
window.addEventListener('error', ...)
is catching the error but the it's limited to the following:
column: 0
error: null
filename:
line: 0
message: Script error
This changes if I set it to webSecurity
to false
then I get:
column: 7
error:
filename:
line: 1
message: Uncaught Error: this is my exception
So the problem is now, webSecurity is disabled, I think this is the best thing to do. And the filename is even now empty, I even now have no clue where it happened.
Trough the debugger
I attached and registered the debugger with the domains: Debugger.enable
and Log.enable
Log.entryAdded
is never received for errors in executeJavaScript
code.
How to reproduce
use the options above then:
webContents.executeJavaScript('throw new Error("this is my exception")')
Same for syntax error or others...
In all examples the start options are (+ changes are described):
Start options: webSecurity: true, nodeIntegration: false, sandbox: false
Yes, this is almost the default config except nodeIntegration.
This is not related to the new sandbox
function, it's false - in sandbox mode it's broken entirely: #9073