chromium / axiom

Axiom Project
https://chromium.github.io/axiom/web_shell/
Apache License 2.0
53 stars 26 forks source link

`chrome --exec-script`: intercept and communicate script errors to user #233

Open ussuri opened 9 years ago

ussuri commented 9 years ago

Right now, chrome --exec-script "some invalid script" ... returns null, rather than printing an informative message to the user about what what's happened. However, the console in the problematic window shows the error just fine. Try wrapping the user's script into a try-catch shell inside chrome_agent_client.js` before sending it for execution to the tab, and returning the caught exception.

Also, to return a result, the script currently must end in a statement that evaluates to that result, e.g. document.querySelector('...'): using return with it (return document.querySelector('...')) creates an error. Using return is rather intuitive, so we should find a way to allow it, e.g. wrap the user's script into a (function() { <script> })();.