-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Better error reporting for webContents->executeJavaScript #9102
Comments
Lot's to read here and not much time, but a quick solution to your error handling issue is to simply make the return type of your executeJavaScript call a Promise. webContents.executeJavaScript('new Promise(() => { throw new Error("this is my exception") })').catch(err => console.warn(err)) |
I will this. However if the code snippet contains syntax errors it's the same problem. I try to catch all kind of errors can happen |
more Error: Promise rejected with value: {} // <- totally useless. windows like behaviour. That's really annoying - because:
How to solve? Temporary solution interface ErrorShape {
name?: string
message?: string
stack?: string
// ...
} snippet: try {
const result await = webContents.executeJavaScript(`
new Promise((resolve, reject) => {
try {
// do stuff...
} catch(err) {
throw { name: err.name, message: err.message, stack: err.stack }
}
})
`)
} catch(errObj) {
// errObj is not an error object but it has the same fields like the basic error object
} |
bump |
@aight8 Please don't "bump" issues, it does nothing other than send annoying emails to people watching the repo 👍 |
a promise based API should either resolve or reject, which corresponds to either moving to the next statement or throwing an exception in sync code. try {
const result = await promiseApi();
// either you end up here
} catch (e) {
// or here, there is no valid third option
} So shouldn't failing without rejecting be considered a bug? |
I feel like I fixed this with the error serialization (#11158). Is that good enough to close this issue? |
#11158 takes care of errors in promise wrapped code, right? If the syntax error is not in wrapped code |
I'm hitting the same issuue as @bughit describes (with latest 3.0.x electron) ....why is there no refused Promise being thrown?! Took several days to debug this promise not working as it should. |
…e script (#18635) * fix: reject the executeJavaScript promise when it fails to execute the script Closes #9102 * Update atom/renderer/api/atom_api_web_frame.cc Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net> * Update atom/renderer/api/atom_api_web_frame.cc Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net> * fix: missing semicolon
…e script (#18714) * fix: reject the executeJavaScript promise when it fails to execute the script Closes #9102 * Update atom/renderer/api/atom_api_web_frame.cc Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net> * Update atom/renderer/api/atom_api_web_frame.cc Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net> * fix: missing semicolon
Unfortunately we cannot get more information from Electron with regards to the nature of the error. In fact, the error that it reports instructs the user to check the JavaScript console within the renderer for more details. You can see more information here: electron/electron#18635 electron/electron#9102
Unfortunately we cannot get more information from Electron with regards to the nature of the error. In fact, the error that it reports instructs the user to check the JavaScript console within the renderer for more details. You can see more information here: electron/electron#18635 electron/electron#9102
Unfortunately we cannot get more information from Electron with regards to the nature of the error. In fact, the error that it reports instructs the user to check the JavaScript console within the renderer for more details. You can see more information here: electron/electron#18635 electron/electron#9102
Unfortunately we cannot get more information from Electron with regards to the nature of the error. In fact, the error that it reports instructs the user to check the JavaScript console within the renderer for more details. For more information, see: electron/electron#18635 electron/electron#9102 Fixes #30.
Unfortunately we cannot get more information from Electron with regards to the nature of the error. In fact, the error that it reports instructs the user to check the JavaScript console within the renderer for more details. For more information, see: electron/electron#18635 electron/electron#9102 Fixes #30.
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:
*) webContents.executeJavaScript function
**)
window.addEventListener('error', function(errorEvent) {})
orwindow.onerror = function(...) {}
***) 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:
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:This changes if I set it to
webSecurity
tofalse
then I get: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
andLog.enable
Log.entryAdded
is never received for errors inexecuteJavaScript
code.How to reproduce
use the options above then:
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: #9073The text was updated successfully, but these errors were encountered: