WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
101504
Web Inspector: make command line API available within snippets.
https://bugs.webkit.org/show_bug.cgi?id=101504
Summary
Web Inspector: make command line API available within snippets.
Pavel Feldman
Reported
2012-11-07 13:02:04 PST
Feedback from the user: as a side question/request, can we get Snippets execute under console's context? I mean access to great stuff like copy(), $0, $1, $_ inside snippet code? I think that would be very useful, currently I end up copy-pasting some of my saved snippets into the console instead of just pressing the play button...
Attachments
Add attachment
proposed patch, testcase, etc.
Dmitry Pashkevich
Comment 1
2012-11-16 06:56:13 PST
Basically I want to be able to save all the cool stuff I can do in console as snippets for further reuse. Obviously the use cases aren't limited to mere logging but also injecting more advanced pieces of code of debugging an application. Here are some of them off the top of my head: * Extract some data from a webpage (current page or fetched via XHR) and output it to console, or better copy() it directly to clipboard * Write some quick validation code and output assertions to console, or maybe copy() directly to clipboard * Perform common tasks specific to js frameworks (see below) * Quickly perform some tasks on html elements by selecting them on the Elements panel and executing a snippet (see below) More concrete examples of snippets I use quite often: // Monitor events on current element monitorEvents($0); // Append an empty div to current element $0.appendChild(document.createElement('div')) // "Duplicate down" current element (function() { function dupeDown(el) { var c = el.cloneNode(true), next = el.nextSibling; c.id && c.removeAttribute('id'); el.parentNode.insertBefore(c, next); // same as appendChild if next is null } dupeDown($0); })(); Some more snippets specific to ExtJS framework: // Get component over selected DOM node Ext.getCmp($0.id); // Capture all component events by selected DOM node in Inspector Ext.util.Observable.capture(Ext.getCmp($0.id), function(evname) {console.log(evname, arguments);}) Ideally I would love if I could tie some of the snippets directly to context menu in Elements panel (or I should just create a browser extension) but Snippets seem like great generic tool for quick hacking.
Dmitry Pashkevich
Comment 2
2012-11-16 06:58:49 PST
By the way, selecting all text in a snippet and clicking "Evaluate in Console" from the context menu (as suggested by Pavel Feldman) doesn't work as expected: the code still doesn't have access to CommandLine API functions like copy().
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug