Skip to content

Commit

Permalink
Show service worker navigation preload requests in DevTools Network tab.
Browse files Browse the repository at this point in the history
Demo: https://youtu.be/I-Qe_Y-xYxE

Navigation Preload requests are initiated from the browser process.
This is different from the normal network requests which are initiated from the
renderer process.

When the DevTools show the normal requests in the Network tab, DevTool's
Network events (requestWillBeSent, responseReceived, loadingFinished etc) are
dispatched via InspectorInstrumentation and InspectorNetworkAgent.

This CL introduces new DevTool's Network events (navigationPreloadSent,
navigationPreloadResponseReceived, navigationPreloadFailed,
navigationPreloadFinished) which are dispatched via InspectorInstrumentation and
InspectorNetworkAgent from ServiceWorkerContextClient.

In the normal requests case, we record the request sending timestamp when the
renderer process will send the request in InspectorNetworkAgent::
willSendRequestInternal(). But in the navigation preload case, we record the
timestamp in the browser process, and send it to the service worker's renderer
process using FetchEventPreloadHandle.

BUG=649558

Review-Url: https://codereview.chromium.org/2620463002
Cr-Commit-Position: refs/heads/master@{#445630}
  • Loading branch information
horo-t authored and Commit bot committed Jan 24, 2017
1 parent 5b9db75 commit 70130f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions front_end/network/NetworkDataGridNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ Network.NetworkRequestNode = class extends Network.NetworkNode {
cell.request = request;
break;

case SDK.NetworkRequest.InitiatorType.Preload:
cell.title = Common.UIString('Preload');
cell.classList.add('network-dim-cell');
cell.appendChild(createTextNode(Common.UIString('Preload')));
break;

default:
cell.title = Common.UIString('Other');
cell.classList.add('network-dim-cell');
Expand Down
2 changes: 2 additions & 0 deletions front_end/sdk/NetworkLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ SDK.NetworkLog = class extends SDK.SDKModel {
scriptId = topFrame.scriptId;
break;
}
} else if (initiator.type === Protocol.Network.InitiatorType.Preload) {
type = SDK.NetworkRequest.InitiatorType.Preload;
}
}

Expand Down
3 changes: 2 additions & 1 deletion front_end/sdk/NetworkRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,8 @@ SDK.NetworkRequest.InitiatorType = {
Other: 'other',
Parser: 'parser',
Redirect: 'redirect',
Script: 'script'
Script: 'script',
Preload: 'preload'
};

/** @typedef {!{name: string, value: string}} */
Expand Down
13 changes: 10 additions & 3 deletions front_end/sdk/SubTargetsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ SDK.SubTargetsManager = class extends SDK.SDKModel {
* @return {number}
*/
_capabilitiesForType(type) {
if (type === 'worker')
return SDK.Target.Capability.JS | SDK.Target.Capability.Log;
if (type === 'worker') {
var capabilities = SDK.Target.Capability.JS | SDK.Target.Capability.Log;
var parentTargetInfo = this.targetInfo(this.target());
var mainIsServiceWorker =
!this.target().parentTarget() && this.target().hasTargetCapability() && !this.target().hasJSCapability();
if ((parentTargetInfo && parentTargetInfo.type === 'service_worker') || mainIsServiceWorker)
capabilities |= SDK.Target.Capability.Network;
return capabilities;
}
if (type === 'service_worker')
return SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target.Capability.Target;
if (type === 'iframe') {
Expand Down Expand Up @@ -163,7 +170,7 @@ SDK.SubTargetsManager = class extends SDK.SDKModel {

// Only pause new worker if debugging SW - we are going through the pause on start checkbox.
var mainIsServiceWorker =
!this.target().parentTarget() && this.target().hasTargetCapability() && !this.target().hasBrowserCapability();
!this.target().parentTarget() && this.target().hasTargetCapability() && !this.target().hasJSCapability();
if (mainIsServiceWorker && waitingForDebugger)
target.debuggerAgent().pause();
target.runtimeAgent().runIfWaitingForDebugger();
Expand Down

0 comments on commit 70130f5

Please sign in to comment.