Bug 157198 - Web Inspector: Issues inspecting the inspector, pausing on breakpoints causes content to not load
Summary: Web Inspector: Issues inspecting the inspector, pausing on breakpoints causes...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-04-29 12:56 PDT by Joseph Pecoraro
Modified: 2016-04-29 18:46 PDT (History)
12 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (15.31 KB, patch)
2016-04-29 17:21 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2016-04-29 12:56:46 PDT
* SUMMARY
Mysterious issues inspecting the inspector, pausing on breakpoints causes content to not load.

* STEPS TO REPRODUCE
1. Inspect <http://bogojoker.com/shell/>
2. Set a breakpoint on formatted easySlider.min.js:56:21 ("if (autoplay)")
3. Select another resource in sidebar (facebox.js)
4. Reload
5. Inspect the inspector
6. inspector^2: Set breakpoint in TextEditor.prototype.revealPosition
7. inspector^1: Select breakpoint in sidebar to reveal its position
  => inspector^2 breakpoint triggers a few times, but ultimately continues
  => inspector^1 content never loads

* NOTES
Some logging and logging of protocol traffic is mysterious:

file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Models/SourceCode.js:113:20: CONSOLE LOG requestContent http://bogojoker.com/shell/js/easySlider.min.js
[native code]: CONSOLE LOG request: {"id":94,"method":"Network.getResponseBody","params":{"requestId":"0.73"}}
file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Models/SourceCode.js:113:20: CONSOLE LOG requestContent http://bogojoker.com/shell/js/easySlider.min.js
file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Views/TextEditor.js:441:20: CONSOLE LOG revealPosition - REVEAL
file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Views/TextEditor.js:433:24: CONSOLE LOG revealPosition - STASH
file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Views/TextEditor.js:441:20: CONSOLE LOG revealPosition - REVEAL
file:///Users/pecoraro/Build/Release/WebInspectorUI.framework/Resources/Models/GarbageCollection.js:32:23: CONSOLE ERROR

We never got a response for Network.getResponseBody. In fact, the promise is still pending within the Resource. How is this possible?
Comment 1 Radar WebKit Bug Importer 2016-04-29 12:57:12 PDT
<rdar://problem/26011049>
Comment 2 Joseph Pecoraro 2016-04-29 15:20:44 PDT
I think I found the issue.

When the Web Inspector itself is paused but the Inspected Page is not paused, then when the Web Inspector Process goes to dispatch a message (evaluating script in the page) we fail.

Here is the chain of events:

    InspectorProcess
      -> sendMessageToBackend( "Network.getResponseBody" )
        -> send Messages::WebInspector::SendMessageToBackend to WebContentProcess

    InspectorProcess
      -> PAUSE evaluating Web Inspector page JavaScript
        -> Run Nested Run Loop

    WebContentProcess
      - receive Messages::WebInspector::SendMessageToBackend message
        -> InspectorNetworkAgent::getResponseBody
          -> InspectorBackendDispatcher::sendMessageToFrontend
            -> WebInspector::sendMessageToFrontend (WebKit2 FrontendClient)
              -> send Messages::WebInspectorUI::SendMessageToFrontend to InspectorProcess

    InspectorProcess* (in nested runloop)
      - receive Messages::WebInspectorUI::SendMessageToFrontend
        -> WebInspectorUI::sendMessageToFrontend
          -> WebInspectorFrontendAPIDispatcher::dispatchMessageAsync
            -> ScriptController::executeScript
              -> Cannot execute script, we are paused, the message NEVER gets sent

So, in this scenario, WebInspectorFrontendAPIDispatcher can queue up messages while the inspector page is paused (something that we don't normally expect).

This also sheds light on another possible issue of APIs (JSContext / WKWebView) attempting to evaluating JavaScript on a paused page will just have their scripts dropped on the floor. However, that has always been the case, so I'm going to address that now.
Comment 3 Joseph Pecoraro 2016-04-29 17:21:54 PDT
Created attachment 277765 [details]
[PATCH] Proposed Fix

Not going to commit-queue until I have tested a Debug build at least once. But this works.

I'm not sure it is perfect (pause/unpause happens while stepping, so in theory you could pause inside the new evaluation in between statements), however in practice InspectorFrontendAPIDispatcher is adding to a queue, so it actually isn't a problem. And again, this is only for inspecting the inspector right now.
Comment 4 BJ Burg 2016-04-29 17:26:45 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=277765&action=review

> Source/WebKit2/WebProcess/WebPage/WebInspectorFrontendAPIDispatcher.cpp:59
> +    ASSERT(m_queue.isEmpty());

This assertion seems wrong. What if evaluating a dequeued expression caused us to hit a breakpoint and suspend?

> Source/WebKit2/WebProcess/WebPage/WebInspectorFrontendAPIDispatcher.cpp:75
> +    evaluateOrQueueExpression(makeString("InspectorFrontendAPI.dispatch([\"", command, "\"])"));

Nit: evaluateOrEnqueueExpression
Comment 5 Joseph Pecoraro 2016-04-29 17:56:07 PDT
(In reply to comment #4)
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=277765&action=review
> 
> > Source/WebKit2/WebProcess/WebPage/WebInspectorFrontendAPIDispatcher.cpp:59
> > +    ASSERT(m_queue.isEmpty());
> 
> This assertion seems wrong. What if evaluating a dequeued expression caused
> us to hit a breakpoint and suspend?

We don't appear to allow pausing when running when already nested. Or at least I was unable to (console.log worked, but hitting a breakpoint did not).
Comment 6 WebKit Commit Bot 2016-04-29 18:46:52 PDT
Comment on attachment 277765 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 277765

Committed r200276: <http://trac.webkit.org/changeset/200276>
Comment 7 WebKit Commit Bot 2016-04-29 18:46:56 PDT
All reviewed patches have been landed.  Closing bug.