-1

So I have this pageerror event handler catching an error, and it's working fine. But if I wanted more details from the stacktrace, I'm not sure how to do it.

Here's what I've written so far

(context: reportStatus is a function that sends a status report to an API endpoint and prints to console as well. It takes the title of the status, and a callback function)

        pupPage.on('pageerror', async (error) => {
        console.log("ERROR'd");
        console.log(Object.getOwnPropertyNames(Object.getPrototypeOf(error)));


        reportStatus('WEB_APPLICATION_ERROR', async function () {
          var stackTrace;

          utl.print('Error message: ' + error);

          // GET THE STACKTRACE THAT CAUSED THE ERROR AND PRINT IT!

          quit();
        });
      });

And this is what I see in the console.

ERROR'd
[ 'constructor', 'name', 'message', 'toString' ]
WEB_APPLICATION_ERROR
Error message: ReferenceError: params is not defined
QUITTING

So I know that the error is a ReferenceError where some "params" variable is not defined. But I want to know more details, like what line in what script caused that error.

Unfortunately, it doesn't seem like the error object has anything related to the stacktrace.

Is there a function I could use to get the stacktrace of the error that triggered the pageerror event?

DatGameh
  • 11
  • 3
  • Try `error.stack`. Your method for getting the available properties and methods on the error object is misleading you. – ggorlen Aug 20 '23 at 06:01
  • @ggorlen Thank you for the advice! Honestly, I have no idea how I could've figured this out without your help. Though, now I have a different problem: I do get the stackerror in the console now but it says `ReferenceError: params is not defined at (:0:0)`. Why is there the 'anonymous(:0:0)? – DatGameh Aug 21 '23 at 13:41
  • I web searched "get stack trace from error JS". Regarding your new question, that's probably from the webpage. I don't know what it is, but is the source minified, and/or is the error thrown in an anonymous function? Is it possible to share the page or create a simple example? – ggorlen Aug 21 '23 at 13:47
  • Hi @ggorlen, sorry for the late reply, but that error seems to be my fault. It's not a problem, thanks for your help! – DatGameh Aug 29 '23 at 19:48

0 Answers0