1

My question is different from the other posts similar to this.

AutoCAD offers developers a means of displaying a URL page inside the application. I created an intranet site for my company with the hopes that users can explore via desktop browser or their AutoCAD application.

The problem is that the browser AutoCAD uses is Chrome version 33 (currently its at 84) - there is no way to update or change the browser either.

I have no way to "inspect" or debug the site inside AutoCAD - and I've come to find out there are many difference in v84 and v33. I'm trying to diagnose errors right now but again, I have no way of accessing the console logs inside the AutoCAD Browser.

Is there a way for me to "alert" any errors that the console is trying to give me? (ie: the page can't find a script reference, there is an unexpected '.', etc...)

NOTE - my site runs great on the most updated Chrome browser (v84 on desktop browser), but some little things are not working right in v33 (in AutoCAD Browser).

2
  • 1
    You can keep your codes inside the try-catch block and have an alert in the catch block. Commented Sep 1, 2020 at 20:47
  • is this using the console.error(...) method? Commented Sep 1, 2020 at 21:17

1 Answer 1

2

If you control the website you can attach a listener on the window to listen for any unhandled exceptions. Add this before all other scripts to make sure everything is captured.

window.on('error', (e) => { // if error is intresting, do work. alert(e.message); }); 

The handler accepts an ErrorEvent object.

NOTE - This will not capture errors that are triggered in scripts across domain. For example if you are loading google maps, and an error is triggered within that script, you will typically get a 'Script error.' and no other info. This has to do with cross origin policies. You can read more here.

If you need to specifically to capture data sent to console.error you can simply proxy the function. This may not capture anything except for code that explicitly calls console.error and is not recommended.

const error = console.error; console.error = (...args) => { // alert(...); error.apply(console, args); } 
Sign up to request clarification or add additional context in comments.

1 Comment

This is great. Unfortunately I can't run es6 on this project, but just revising it to window.addEventListenter('error', function(e) { alert(e.message); }); did the trick. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.