New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 680116 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Jan 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Feature



Sign in to add a comment

Allow $0 in spippets

Reported by ovkadu...@gmail.com, Jan 11 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2978.0 Safari/537.36

Steps to reproduce the problem:
1. Go to Elements panel. Select any element
2. Create a snippet
3. Paste console.log($0);
4. Select the code. 
5. Right click -> Evaluate in console
6. Console says "VM203:1 Uncaught ReferenceError: $0 is not defined"

What is the expected behavior?
So if it's possible to run script from inside console, I would love to have ability to use those $0 (and others) variables.

One of useful example:
$($0).click(function () {
   console.log("button is clicked");
);

What went wrong?
It doesn't allow $0 in snippets.

Did this work before? N/A 

Chrome version: 57.0.2978.0  Channel: canary
OS Version: 10.0
Flash Version: Shockwave Flash 24.0 r0
 

Comment 1 by alph@chromium.org, Jan 11 2017

Labels: -Type-Bug Type-Feature
Owner: kozyatinskiy@chromium.org
Status: Assigned (was: Unconfirmed)
Just wondering, why do you use select the code -> evaluate in console instead of "Ctrl + Enter" or just play button in bottom right corner of snippet source? 
Status: Started (was: Assigned)
https://codereview.chromium.org/2645723002/

Comment 4 by ovkadu...@gmail.com, Jan 18 2017

>>>Just wondering, why do you use select the code -> evaluate in console instead of "Ctrl + Enter" or just play button in bottom right corner of snippet source? 

Running via "evaluate in console" gives access to the lexical scope variables.
So I might want to stop the code inside a function and run in the snippets something like this:
$("#btn").click(function () {
    console.log("Current state of the internal internal is: " + internal1);
);

The function might look like this:
function () {
    var internal1 = 45;
    // here I can set stop the code execution in order to run "evaluate in console".
    return {
        setInternal: function (val) {
            internal1 = val;
        },
        getComputedInternal: function () {
            return internal1 * 2;
        }
    }
}
Status: Fixed (was: Started)
I see, thanks for description!

Comment 7 by ovkadu...@gmail.com, Jan 20 2017

It works. Thank you!

Comment 8 by kayce@google.com, Jan 26 2017

Labels: DevTools-Release-Notes-Feature

Sign in to add a comment