Looking at this question, it is possible to retrieve the path of the current source file by accessing the last <script>
element in the document during initialization.
This works fine, however I am working with react and transpiling my source files with babel. So instead of getting the original source file name, the above solution would get me something like 'bundle.js' which means very little to me.
To give some context, I am trying to enable/disable logging at the switch of a bool by overriding console
's log
and dir
functions. If this functionality is described in say debug.js
, then the source for my logs (as specified in the console) will be that file. So I'd like to log an extra piece of information to say which file the call to console.log
occurred.