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

Issue 646849 link

Starred by 4 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 29
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Feature



Sign in to add a comment

Identify where eval'ed code was eval'ed.

Project Member Reported by tdres...@chromium.org, Sep 14 2016

Issue description

In devtools, I'm often trying to figure out where some piece of code came from, for example, an event listener.

Fairly frequently, the event listener code was eval'ed, so I bottom out in a file like "VM698:2".

Ideally, I'd be able to figure out where this code came from, perhaps by right clicking on the tab for the source.

This will be valuable for web devs trying to figure out which third party on their site added some logic.
 
Labels: OS-All
Owner: kozyatinskiy@chromium.org
Status: Assigned (was: Untriaged)
Cc: chowse@chromium.org
We can expose a stack trace that led to anonymous script execution but I'm not sure how we can show this stack trace in UI.
Chris, WDYT?

Comment 3 by chowse@chromium.org, Sep 27 2016

The Network panel's initiator stack trace popup would seem like a good fit for this. When you hover over an initiator link in the Network panel, a popup appears showing a stack trace of where that resource was injected. This lets you both go straight to the injection site (clicking on the link) or any point leading up to where it was added (using the popup). See the first attached screenshot.

So where could this go? How about the footer of the editor? For VM files, add another component beside the line/column number, labelled "Injected from [source file]". "[Source file]" here would be the initiator link. Clicking on the link would open the source file (at the point of injection) in a new window. Hovering over the link would show the stack trace that lead to the injection. See the second attached screenshot.

Would this work?
network-initiator-stack-trace.png
169 KB View Download
b646849-inject-footer.png
139 KB View Download
This looks fantastic to me.
Cc: lanwei@chromium.org

Comment 6 by lanwei@chromium.org, Oct 20 2016

We are collecting the information of scripts which handles touch events, here is the patch https://codereview.chromium.org/2320573006/diff/220001/third_party/WebKit/Source/bindings/core/v8/V8EventListener.cpp

I got an empty script url, when eval is used, and we want to get the actual script url. Is there any V8 functions, we can use to get the call stack? Thank you. 

Comment 7 Deleted

I'm not sure that this issue is related. We're going to add additional call stack argument into scriptParsed js_protocol.json event to be able to show this stack for scripts in DevTools frontend.

What do you mean by actual script url? Url of last not anonymous frame in stack trace?
To get stack trace you can use v8::StackTrace::CurrentStackTrace from v8.h, you can get frame from it by GetFrame call and then get url by GetScriptNameOrSourceURL call on frame.
Another possible solution is expose way to iterate through frames on v8_inspector::V8StackTrace and then get this by calling takeStackTrace on SourceLocation.

Comment 9 by lanwei@chromium.org, Oct 20 2016

It is related, Tim was asking how to see from DevTools. We thought we did not need to go over every website, and we could just use devtool to track the scripts. Now we are hoping do to it automatically in the code, I will look at the functions you suggested. 

http://o.aolcdn.com/os/moat/prod/moatuac.js is the actual script Url that calls eval in www.aol.com, but now we only get empty string from SourceLocation's url(). Because we are getting the function information from ScriptState, do you think we can find the frame and the stack trace?
Owner: kozy@chromium.org
Project Member

Comment 12 by bugdroid1@chromium.org, Aug 25

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/cc09ed9dfa66c1c27020fafe36c07601b947d2ad

commit cc09ed9dfa66c1c27020fafe36c07601b947d2ad
Author: Alexey Kozyatinskiy <kozyatinskiy@chromium.org>
Date: Sat Aug 25 21:39:58 2018

DevTools: show origin url for anonymous scripts

R=lushnikov@chromium.org

Bug:  chromium:646849 
Change-Id: I8141bcdcfef7d9734ee9f1c97bfa552160fdcd9d
Reviewed-on: https://chromium-review.googlesource.com/1182865
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586149}
[add] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/WebKit/LayoutTests/http/tests/devtools/sources/source-frame-toolbar-items-expected.txt
[add] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/WebKit/LayoutTests/http/tests/devtools/sources/source-frame-toolbar-items.js
[modify] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/BUILD.gn
[modify] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/front_end/sdk/DebuggerModel.js
[modify] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/front_end/sdk/Script.js
[add] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/front_end/sources/ScriptOriginPlugin.js
[modify] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/front_end/sources/UISourceCodeFrame.js
[modify] https://crrev.com/cc09ed9dfa66c1c27020fafe36c07601b947d2ad/third_party/blink/renderer/devtools/front_end/sources/module.json

Status: Fixed (was: Assigned)

Sign in to add a comment