Since the chrome dev tools is blocked on my school computer (a chromebook), I have to build my own dev tools for debugging.
I chose to use a html file for debugging. This is what I have now: a giant textarea for source code, a console for debugging, and an iframe for displaying my result.
I want to view the call stack whenever log()
is called in the iframe. Here's the code I have for logging (as a replacement for console.log
):
outputIframe.contentWindow.log = function(tobelogged) {
consoleDisplay((new Error).stack); //for getting the stack trace https://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-how-to-get-javascript-caller
consoleDisplay(tobelogged);
}
However, this is the result:
Source code input: <html><body><script>function abc(){log(123);};abc()</script></body></html>
Console output:
< Error
at outputIframe.contentWindow.log (<anonymous>:244:34)
at refresh (<anonymous>:260:47)
at HTMLIFrameElement.outputIframe.onmouseenter (<anonymous>:235:25)
--------------------------------------------------------------------------
< 123
This is what I want:
< Error
at abc (<anonymous>:1:16)
at <anonymous>:1:27
--------------------------------------------------------------------------
< 123
or:
< 123
at log (somewhere:1:16) //this line actually does not matter
at abc (<anonymous>:1:16)
at <anonymous>:1:27
In short, I want to access the call stack inside an iframe. Any ideas?
Thank you in advance.
P.S. Since my computer is a chromebook, I don't need browser compatibility. The browser I'm using is always the latest version of google chrome.