RESOLVED FIXED Bug 17240
Web Inspector: implement blackboxing of script resources
https://bugs.webkit.org/show_bug.cgi?id=17240
Summary Web Inspector: implement blackboxing of script resources
Adam Roben (:aroben)
Reported 2008-02-08 14:04:02 PST
The JS call stack can easily become very long and filled with frames you don't really care about if you're using a JS framework on your site (e.g., jQuery, Protoype, etc.). It would be nice if Drosera let you collapse/omit the frames from a specific framework. Maybe we could just show the entry/exits points to/from a particular file and skip any calls within that file.
Attachments
Patch (36.58 KB, patch)
2019-06-14 01:28 PDT, Devin Rousso
no flags
Archive of layout-test-results from ews105 for mac-highsierra-wk2 (2.92 MB, application/zip)
2019-06-14 02:24 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews101 for mac-highsierra (3.18 MB, application/zip)
2019-06-14 02:40 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews112 for mac-highsierra (3.03 MB, application/zip)
2019-06-14 03:18 PDT, EWS Watchlist
no flags
Patch (67.23 KB, patch)
2019-06-14 17:29 PDT, Devin Rousso
no flags
Archive of layout-test-results from ews103 for mac-highsierra (3.20 MB, application/zip)
2019-06-14 18:41 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews105 for mac-highsierra-wk2 (2.77 MB, application/zip)
2019-06-14 18:49 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews114 for mac-highsierra (3.04 MB, application/zip)
2019-06-14 19:20 PDT, EWS Watchlist
no flags
Patch (67.65 KB, patch)
2019-06-14 19:34 PDT, Devin Rousso
no flags
Archive of layout-test-results from ews105 for mac-highsierra-wk2 (2.72 MB, application/zip)
2019-06-14 20:53 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews112 for mac-highsierra (2.98 MB, application/zip)
2019-06-14 21:25 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews103 for mac-highsierra (3.18 MB, application/zip)
2019-06-15 02:23 PDT, EWS Watchlist
no flags
Patch (54.96 KB, patch)
2019-08-04 21:08 PDT, Devin Rousso
no flags
Patch (68.21 KB, patch)
2019-08-08 16:14 PDT, Devin Rousso
ews-watchlist: commit-queue-
Archive of layout-test-results from ews102 for mac-highsierra (3.48 MB, application/zip)
2019-08-08 17:27 PDT, EWS Watchlist
no flags
Patch (68.21 KB, patch)
2019-08-08 17:43 PDT, Devin Rousso
no flags
Patch (73.53 KB, patch)
2019-08-29 17:12 PDT, Devin Rousso
no flags
[Image] After Patch is applied (1.16 MB, image/png)
2019-08-29 17:12 PDT, Devin Rousso
no flags
Patch (74.58 KB, patch)
2019-09-03 17:19 PDT, Devin Rousso
no flags
Adam Roben (:aroben)
Comment 1 2008-02-08 14:19:33 PST
Blaze Burg
Comment 2 2014-01-12 14:53:02 PST
Firefox devtools implements this: https://hacks.mozilla.org/2013/08/new-features-of-firefox-developer-tools-episode-25/ It allows you to blackbox JS frameworks, making their call frames omitted or reduced when paused in the debugger.
Blaze Burg
Comment 3 2014-01-25 15:10:58 PST
*** Bug 59119 has been marked as a duplicate of this bug. ***
Blaze Burg
Comment 4 2014-01-26 10:29:49 PST
*** Bug 80383 has been marked as a duplicate of this bug. ***
Yehuda Katz
Comment 5 2014-01-26 21:19:18 PST
I added this comment to a bug that was marked as a duplicate of this one: Brian, I worked with Firefox on this feature and opened up a number of subsequent requests for more granular control over the black-boxing. For example, when I'm debugging Ember itself, even though I want to step through Ember source, I still want to jump through our implementation of forEach and the extra function wrapper we need to create for super (which are *never* the source of bugs). My ideal implementation would support whole-file blackboxing, blackboxing based on an identifier provided by the script (//# blackboxId=ember), and finally per-function blackboxing via sourcemaps (or if that's not possible, via dynamic tagging).
Timothy Hatcher
Comment 6 2016-02-10 15:53:23 PST
We should support source map level blackboxing. Per-function blackboxing is interesting, but might make for a complex UX.
Blaze Burg
Comment 7 2017-05-24 09:11:03 PDT
*** Bug 66632 has been marked as a duplicate of this bug. ***
Emanuele Feliziani
Comment 8 2018-12-11 06:26:41 PST
I'm jumping in to suggest folder-level blackboxing or even pattern-based, just as you have in Chrome. With today's JavaScript stacks, it's more convenient to just blackbox everything within node_modules.
Devin Rousso
Comment 9 2019-06-14 01:28:01 PDT
Created attachment 372117 [details] Patch I'm going to add support for regex/pattern blackboxing via the Settings tab in a followup. I'll also add more tests when I'm more awake -.-
EWS Watchlist
Comment 10 2019-06-14 01:29:17 PDT
This patch modifies the inspector protocol. Please ensure that any frontend changes appropriately use feature checks for new protocol features.
EWS Watchlist
Comment 11 2019-06-14 01:29:28 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 12 2019-06-14 02:24:00 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 13 2019-06-14 02:24:02 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 14 2019-06-14 02:40:04 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 15 2019-06-14 02:40:06 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 16 2019-06-14 03:18:57 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 17 2019-06-14 03:18:59 PDT Comment hidden (obsolete)
Devin Rousso
Comment 18 2019-06-14 17:29:21 PDT
EWS Watchlist
Comment 19 2019-06-14 17:31:39 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 20 2019-06-14 18:41:16 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 21 2019-06-14 18:41:18 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 22 2019-06-14 18:49:18 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 23 2019-06-14 18:49:20 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 24 2019-06-14 19:20:54 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 25 2019-06-14 19:20:56 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 26 2019-06-14 19:28:29 PDT Comment hidden (obsolete)
Devin Rousso
Comment 27 2019-06-14 19:34:51 PDT
EWS Watchlist
Comment 28 2019-06-14 19:38:03 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 29 2019-06-14 20:53:28 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 30 2019-06-14 20:53:30 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 31 2019-06-14 21:25:49 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 32 2019-06-14 21:25:51 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 33 2019-06-15 02:23:01 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 34 2019-06-15 02:23:03 PDT Comment hidden (obsolete)
Devin Rousso
Comment 35 2019-06-24 19:39:26 PDT
Comment on attachment 372168 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372168&action=review > Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:179 > + return InspectorBackend.domains.Debugger.setShouldBlackboxURL; This should `!!` to not return the actual function. > Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:404 > + target.DebuggerAgent.setShouldBlackboxURL(sourceCode.contentIdentifier, !!shouldBlackbox); This should check `if (target.DebuggerAgent.setShouldBlackboxURL)`.
Devin Rousso
Comment 36 2019-08-04 21:08:48 PDT
EWS Watchlist
Comment 37 2019-08-04 21:11:52 PDT Comment hidden (obsolete)
Blaze Burg
Comment 38 2019-08-08 13:21:37 PDT
Comment on attachment 375517 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=375517&action=review You forgot to include SourceCodeTreeElement.css in your patch, so I can't test it out (rendering is really off). > Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:184 > + // FIXME: Handle other backend pause reasons. Like what?
Devin Rousso
Comment 39 2019-08-08 16:12:03 PDT
Comment on attachment 375517 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=375517&action=review >> Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:184 >> + // FIXME: Handle other backend pause reasons. > > Like what? Not sure :P This was moved from below. I'll remove it.
Devin Rousso
Comment 40 2019-08-08 16:14:54 PDT
EWS Watchlist
Comment 41 2019-08-08 16:18:14 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 42 2019-08-08 17:27:19 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 43 2019-08-08 17:27:21 PDT Comment hidden (obsolete)
Devin Rousso
Comment 44 2019-08-08 17:43:49 PDT
Created attachment 375870 [details] Patch Never in my life have I hated a period as much as this moment -.-
EWS Watchlist
Comment 45 2019-08-08 17:45:00 PDT Comment hidden (obsolete)
Devin Rousso
Comment 46 2019-08-15 14:13:11 PDT
Comment on attachment 375870 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=375870&action=review > Source/WebInspectorUI/UserInterface/Views/SourceCodeTreeElement.css:29 > + content: url(../Images/Eye.svg); This should use `Hide.svg` from <https://webkit.org/b/200736>.
Joseph Pecoraro
Comment 47 2019-08-29 16:23:18 PDT
Comment on attachment 375870 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=375870&action=review > Source/JavaScriptCore/debugger/Debugger.cpp:742 > + if (blackboxTypeIterator != m_blackboxedScripts.end() && blackboxTypeIterator->value == BlackboxType::Deferred) { The only type the blackboxTypeIterator value can be at this point is Deferred. So we could assert instead. Up to you though. ASSERT(blackboxTypeIterator->value == BlackboxType::Deferred); > Source/JavaScriptCore/debugger/Debugger.cpp:749 > - PauseReasonDeclaration reason(*this, didHitBreakpoint ? PausedForBreakpoint : m_reasonForPause); > + PauseReasonDeclaration reason(*this, afterBlackboxedScript ? PausedAfterBlackboxedScript : (didHitBreakpoint ? PausedForBreakpoint : m_reasonForPause)); I find double ternaries very hard to read. Could we pull this out? auto pauseReason = m_reasonForPause; if (afterBlackboxedScript) pauseReason = PausedAfterBlackboxedScript; else if (didHitBreakpoint) pauseReason = PausedForBreakpoint; > Source/JavaScriptCore/debugger/Debugger.h:114 > + enum class BlackboxType { For very few values like this I feel it is often better to put it on a single line. It simplifies wasted vertical space and it also helps with code search; searching for "BlackboxType" you get back a single line with all the info you need. > Source/JavaScriptCore/debugger/Debugger.h:246 > + bool m_afterBlackboxedScript { false }; This really didn't read well for me above. Something like `m_steppingThroughBlackboxedScript` seems clearer. > Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:194 > + m_lastBreakReason = m_breakReason; > + m_lastBreakData = WTFMove(m_breakData); These could be named `m_preBlackboxBreakReason` etc given they are not always the "last" value. > Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:894 > + errorString = "Blackboxing of internal scripts is controlled by 'setPauseForInternalScripts'"; Nit: `_s` suffix > Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:952 > + if (m_pauseForInternalScripts) > + m_scriptDebugServer.setBlackboxType(sourceID, WTF::nullopt); > + else > + m_scriptDebugServer.setBlackboxType(sourceID, JSC::Debugger::BlackboxType::Ignored); > + } You could avoid this if by pulling the Blackbox type out of the loop! auto type = m_pauseForInternalScripts ? JSC::Debugger::BlackboxType::Ignored : WTF::nullopt; for (auto& [sourceID, script] : m_scripts) { if (!isWebKitInjectedScript(script.sourceURL)) continue; m_scriptDebugServer.setBlackboxType(sourceId, type); } > Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:1081 > + data->setString("originalReason", Protocol::InspectorHelpers::getEnumConstantValue(DebuggerFrontendDispatcher::Reason::Breakpoint)); > + data->setValue("originalData", buildBreakpointPauseReason(debuggerBreakpointId)); These setter strings could all use `_s` suffix. The `_s` ASCIILiteral path lets us avoid string copies. > Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.h:168 > + void updateBreakReasonAndData(DebuggerFrontendDispatcher::Reason, RefPtr<JSON::Object>&& data); I wonder if now would be a good time to rename all these "break" things to "pause". `updatePauseReasonAndData`, `m_pauseReason`, etc. > Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js:409 > + this.dispatchEventToListeners(DebuggerManager.Event.BlackboxedURLsChanged); We generally prefer dispatching the event after the work (so after the target messages below). > Source/WebInspectorUI/UserInterface/Test/TestHarness.js:214 > if (e) Style: this `if` should have braces.
Devin Rousso
Comment 48 2019-08-29 17:10:25 PDT
Comment on attachment 375870 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=375870&action=review >> Source/JavaScriptCore/debugger/Debugger.cpp:742 >> + if (blackboxTypeIterator != m_blackboxedScripts.end() && blackboxTypeIterator->value == BlackboxType::Deferred) { > > The only type the blackboxTypeIterator value can be at this point is Deferred. So we could assert instead. Up to you though. > > ASSERT(blackboxTypeIterator->value == BlackboxType::Deferred); I'd rather not, just in case we add more types in the future (less code would need to be changed). >> Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:1081 >> + data->setValue("originalData", buildBreakpointPauseReason(debuggerBreakpointId)); > > These setter strings could all use `_s` suffix. The `_s` ASCIILiteral path lets us avoid string copies. Oops. My mistake. >> Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.h:168 >> + void updateBreakReasonAndData(DebuggerFrontendDispatcher::Reason, RefPtr<JSON::Object>&& data); > > I wonder if now would be a good time to rename all these "break" things to "pause". `updatePauseReasonAndData`, `m_pauseReason`, etc. I like it!
Devin Rousso
Comment 49 2019-08-29 17:12:27 PDT
Devin Rousso
Comment 50 2019-08-29 17:12:42 PDT
Created attachment 377656 [details] [Image] After Patch is applied
Joseph Pecoraro
Comment 51 2019-09-03 16:01:07 PDT
Comment on attachment 377655 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=377655&action=review r=me! > Source/WebInspectorUI/UserInterface/Views/SourceCodeTreeElement.js:168 > + WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.BlackboxedURLsChanged, this._updateToggleBlackboxImageElementState, this); It looks like this (updateStatus) can get called multiple times and might add multiple event listeners. I also don't see this event listener getting removed, so these would leak. Perhaps this should create the image element, listener, and set the status once. Then just call update in the general case. > LayoutTests/inspector/debugger/setShouldBlackboxURL.html:63 > + InspectorProtocol.sendCommand(`Debugger.resume`, {}, function(response) { > + InspectorProtocol.checkForError(response); > + }); I think this pattern can be written in a few places like so: InspectorProtocol.sendCommand(`Debugger.resume`, {}, InspectorProtocol.checkForError); Perhaps even making a `InspectorProtocol` convenience: InspectorProtocol.sendCommandAndCheckForError(`Debugger.resume`);
Devin Rousso
Comment 52 2019-09-03 17:18:00 PDT
Comment on attachment 377655 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=377655&action=review >> Source/WebInspectorUI/UserInterface/Views/SourceCodeTreeElement.js:168 >> + WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.BlackboxedURLsChanged, this._updateToggleBlackboxImageElementState, this); > > It looks like this (updateStatus) can get called multiple times and might add multiple event listeners. > > I also don't see this event listener getting removed, so these would leak. > > Perhaps this should create the image element, listener, and set the status once. Then just call update in the general case. Good catch! I'll rework this a bit to be slightly more smart about when it listens for `WI.DebuggerManager.Event.BlackboxedURLsChanged`. As far as the leak issue, that's not really something that's "supported" with the current design of our tree elements/outlines (e.g. `ondetached` only gets called when that tree element gets removed from its parent, not whenever it's removed from the DOM). I think this is better handled by <https://webkit.org/b/196956>.
Devin Rousso
Comment 53 2019-09-03 17:19:02 PDT
WebKit Commit Bot
Comment 54 2019-09-03 19:26:44 PDT
Comment on attachment 377935 [details] Patch Clearing flags on attachment: 377935 Committed r249450: <https://trac.webkit.org/changeset/249450>
WebKit Commit Bot
Comment 55 2019-09-03 19:26:47 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.