Bug 117639 - Web Inspector: Ability to trace execution of JS to console without stepping through in debugger
Summary: Web Inspector: Ability to trace execution of JS to console without stepping t...
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-06-14 06:26 PDT by Gary Weaver
Modified: 2016-02-11 20:31 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Weaver 2013-06-14 06:26:26 PDT
Ruby has Tracer and set_trace_func that both allow the ability to with trace each line of Ruby (file pathname, line#, and full line of code that is being executed) to stdout in the case of Tracer, or to call a proc with event, file, line, id, binding, classname in the case of set_trace_func.

I am looking for something similar, such that when Javascript is executed by WebKit, I could have it log everything to its console, or I could hook into events that would occur when every part of the Javascript code that is being executed.

Ariya of PhantomJS said that WebKit does not currently provide this ability: https://github.com/ariya/phantomjs/issues/11404#issuecomment-19435558

There may be a way to do this via remote debugging, but it seems geared toward the inspector UI/typical case of UI debugging vs. just logging or calling a method on a listener or listeners at each point in the JS execution (i.e. why write something that can act as a remote debugger just to have it constantly send requests to step through each line just to log it when there could be a way to do that in WebKit itself?). So, I'm wondering if there is something that could be added to WebKit to make either one of these possible (and just logging each line of the executed stack to console in a way that could being redirected to stdout when run via PhantomJS would be fine, I think).

The use case is that I'm running Jasmine tests in a terminal (in OS X) and I want to be able to turn on something that logs Javascript that is being executed to stdout. I know that this may seem out of scope, but it would really help those that want to write and test Javascript in terminal only without a user-driven debugger.
Comment 1 Radar WebKit Bug Importer 2013-06-14 09:37:20 PDT
<rdar://problem/14156744>
Comment 2 Antoine Quint 2013-06-14 18:46:40 PDT
There are JS tools that can instrument your code to do what you want (from what I understand anyway). Have you seen http://siliconforks.com/jscoverage/?
Comment 3 Gary Weaver 2013-09-11 18:00:19 PDT
Thanks, but I'm not looking for a code coverage utility.

I wanted to be able to hook into Javascript execution to be able to write to console.out instead of debugging with the browser's developer tools. Having a way to trace the execution to the console (or in the case of PhantomJS, it could log it to the terminal console) and filter it also would be awesome.

It isn't enough to just use Javascript to do it. Here are two attempts I made:

The first tried to hook into the function prototype, but that is bad news- AngularJS and similar don't play well:

https://github.com/garysweaver/autolog.js

The second just changes the JS code you give it to log to console:

https://github.com/garysweaver/noisify

It would be really helpful to have something instead like these that are offered in Ruby, but to do it via the Webkit API, since it isn't likely to be added in Javascript anytime soon:

http://www.ruby-doc.org/core-2.0.0/TracePoint.html
http://www.ruby-doc.org/stdlib-2.0/libdoc/tracer/rdoc/Tracer.html
http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-set_trace_func
Comment 4 BJ Burg 2015-11-20 13:46:32 PST
As a log-spam type thing, this is really out of scope for Web Inspector UI.