8

Im currently writing a wrapper upon chrome’s console object in order to provide equal functionality within web workers which, at least for now, do not support logging yet.

Once the worker notifies the main thread, i replicate the log call with something like:

Function.prototype.apply.call(console.log, console, [workerLogObject])

At this point though, chrome recognizes the call and references file, line and column within the console itself (on the right). The displayed information by definition of console.log uses whatever resource the method has been called in — in my case the wrapper.

Back to the question, is it possible to change the file reference when calling methods of the console object in order to display another file like the web worker in my case? enter image description here

ivoputzer
  • 6,427
  • 1
  • 25
  • 43
  • None that I've ever found and I've looked.... – Jeremy J Starcher Mar 30 '14 at 00:00
  • @JeremyJStarcher sounds like bad news... can you tell if there's a way to force console urls like `http://0.0.0.0/js/testworker.js:5:11` to open with chrome devtools instead of plain tabs instead? – ivoputzer Mar 30 '14 at 00:12
  • possible duplicate of [How to debug web workers](http://stackoverflow.com/questions/2323778/how-to-debug-web-workers) – Oleg Apr 02 '14 at 06:24

1 Answers1

0

try throwing an exception from a worker instead of logging to console. I have not tried this, but you might be able to get exact line number and file location

throw 'a debug message';

clearly this will terminate the execution block so make sure to do the actual work ahead of it.

dbrin
  • 15,525
  • 4
  • 56
  • 83
  • I know how to get the file and line number. I just do something like `(new Error).stack` and lookup through the callees though your solution might be nicer. What i need is to push this information to `console.log` in order to prevent showing always the wrong file-info – ivoputzer Apr 02 '14 at 13:55