Commit 0913e140 authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

[DevTools] Add initiator and priority to HAR importing and exporting

This patch adds two fields, _initiator and _priority, to each entry in
each HAR file. I chose to use underscores in the exported names because
they are not part of the HAR standard and the other non-standard fields
we export also have underscores.

I tested by importing this new type of HAR file in chrome 69, importing
a chrome 69 HAR file with this new patch applied, and by exporting and
importing with all types of initiators.

Bug: 654536
Change-Id: Ibd96eb6374900f29b03880d3292933b539708f18
Reviewed-on: https://chromium-review.googlesource.com/1232374
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594456}
parent 2db1e468
...@@ -8,6 +8,8 @@ Page reloaded. ...@@ -8,6 +8,8 @@ Page reloaded.
} }
entries : [ entries : [
{ {
_initiator : <object>
_priority : <string>
cache : { cache : {
} }
connection : <string> connection : <string>
...@@ -103,6 +105,8 @@ Page reloaded. ...@@ -103,6 +105,8 @@ Page reloaded.
timings : <object> timings : <object>
} }
{ {
_initiator : <object>
_priority : <string>
cache : { cache : {
} }
connection : <string> connection : <string>
......
...@@ -25,6 +25,12 @@ Resource:{ ...@@ -25,6 +25,12 @@ Resource:{
} }
} }
HAR:{ HAR:{
_initiator : {
lineNumber : 117
type : "parser"
url : "http://example.com/inspector-test.js"
}
_priority : "VeryHigh"
cache : { cache : {
} }
request : { request : {
......
...@@ -25,9 +25,16 @@ ...@@ -25,9 +25,16 @@
request.statusText = 'OK'; request.statusText = 'OK';
request.resourceSize = 1000; request.resourceSize = 1000;
request._transferSize = 539; // 39 = header size at the end of the day request._transferSize = 539; // 39 = header size at the end of the day
request.setPriority('VeryHigh');
} }
var testRequest = new SDK.NetworkRequest('testRequest', 'http://example.com/inspector-test.js', 1); const fakeInitiator = {
type: 'parser',
url: 'http://example.com/inspector-test.js',
lineNumber: 117
};
var testRequest = new SDK.NetworkRequest(
'testRequest', 'http://example.com/inspector-test.js', 'http://example.com/fake-document-url', 1, 1, fakeInitiator);
setRequestValues(testRequest); setRequestValues(testRequest);
var headersText = testRequest.requestHeadersText(); var headersText = testRequest.requestHeadersText();
var requestResults = { var requestResults = {
......
...@@ -2,6 +2,8 @@ Tests that resources panel shows form data parameters. ...@@ -2,6 +2,8 @@ Tests that resources panel shows form data parameters.
http://127.0.0.1:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1&queryParam2= http://127.0.0.1:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1&queryParam2=
{ {
_initiator : <object>
_priority : <string>
cache : { cache : {
} }
connection : <string> connection : <string>
......
...@@ -2,6 +2,8 @@ Tests that resources panel shows form data parameters. ...@@ -2,6 +2,8 @@ Tests that resources panel shows form data parameters.
http://[::1]:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1&queryParam2= http://[::1]:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1&queryParam2=
{ {
_initiator : <object>
_priority : <string>
cache : { cache : {
} }
connection : <string> connection : <string>
......
...@@ -160,6 +160,9 @@ HARImporter.HAREntry = class extends HARImporter.HARBase { ...@@ -160,6 +160,9 @@ HARImporter.HAREntry = class extends HARImporter.HARBase {
// Chrome specific. // Chrome specific.
this._fromCache = HARImporter.HARBase._optionalString(data['_fromCache']); this._fromCache = HARImporter.HARBase._optionalString(data['_fromCache']);
if (data['_initiator'])
this._initiator = new HARImporter.HARInitiator(data['_initiator']);
this._priority = HARImporter.HARBase._optionalString(data['_priority']);
} }
}; };
...@@ -313,3 +316,17 @@ HARImporter.HARTimings = class extends HARImporter.HARBase { ...@@ -313,3 +316,17 @@ HARImporter.HARTimings = class extends HARImporter.HARBase {
this._blocked_proxy = HARImporter.HARBase._optionalNumber(data['_blocked_proxy']); this._blocked_proxy = HARImporter.HARBase._optionalNumber(data['_blocked_proxy']);
} }
}; };
HARImporter.HARInitiator = class extends HARImporter.HARBase {
/**
* Based on Initiator defined in browser_protocol.pdl
*
* @param {*} data
*/
constructor(data) {
super(data);
this.type = HARImporter.HARBase._optionalString(data['type']);
this.url = HARImporter.HARBase._optionalString(data['url']);
this.lineNumber = HARImporter.HARBase._optionalNumber(data['lineNumber']);
}
};
...@@ -22,7 +22,18 @@ HARImporter.Importer = class { ...@@ -22,7 +22,18 @@ HARImporter.Importer = class {
for (const entry of log.entries) { for (const entry of log.entries) {
let pageLoad = pageLoads.get(entry.pageref); let pageLoad = pageLoads.get(entry.pageref);
const documentURL = pageLoad ? pageLoad.mainRequest.url() : entry.request.url; const documentURL = pageLoad ? pageLoad.mainRequest.url() : entry.request.url;
const request = new SDK.NetworkRequest('har-' + requests.length, entry.request.url, documentURL, '', '', null);
let initiator = null;
if (entry._initiator) {
initiator = {
type: entry._initiator.type,
url: entry._initiator.url,
lineNumber: entry._initiator.lineNumber
};
}
const request = new SDK.NetworkRequest(
'har-' + requests.length, entry.request.url, documentURL, '', '', initiator);
const page = pages.get(entry.pageref); const page = pages.get(entry.pageref);
if (!pageLoad && page) { if (!pageLoad && page) {
pageLoad = HARImporter.Importer._buildPageLoad(page, request); pageLoad = HARImporter.Importer._buildPageLoad(page, request);
...@@ -112,6 +123,10 @@ HARImporter.Importer = class { ...@@ -112,6 +123,10 @@ HARImporter.Importer = class {
resourceType = Common.ResourceType.fromURL(entry.request.url) || Common.resourceTypes.Other; resourceType = Common.ResourceType.fromURL(entry.request.url) || Common.resourceTypes.Other;
request.setResourceType(resourceType); request.setResourceType(resourceType);
const priority = entry.customAsString('priority');
if (Protocol.Network.ResourcePriority.hasOwnProperty(priority))
request.setPriority(/** @type {!Protocol.Network.ResourcePriority} */ (priority));
request.finished = true; request.finished = true;
} }
......
...@@ -170,7 +170,9 @@ NetworkTestRunner.HARPropertyFormatters = { ...@@ -170,7 +170,9 @@ NetworkTestRunner.HARPropertyFormatters = {
version: 'formatAsTypeName', version: 'formatAsTypeName',
wait: 'formatAsTypeName', wait: 'formatAsTypeName',
_transferSize: 'formatAsTypeName', _transferSize: 'formatAsTypeName',
_error: 'skip' _error: 'skip',
_initiator: 'formatAsTypeName',
_priority: 'formatAsTypeName'
}; };
NetworkTestRunner.HARPropertyFormattersWithSize = JSON.parse(JSON.stringify(NetworkTestRunner.HARPropertyFormatters)); NetworkTestRunner.HARPropertyFormattersWithSize = JSON.parse(JSON.stringify(NetworkTestRunner.HARPropertyFormatters));
......
...@@ -149,6 +149,16 @@ SDK.HARLog.Entry = class { ...@@ -149,6 +149,16 @@ SDK.HARLog.Entry = class {
for (const t of [timings.blocked, timings.dns, timings.connect, timings.send, timings.wait, timings.receive]) for (const t of [timings.blocked, timings.dns, timings.connect, timings.send, timings.wait, timings.receive])
time += Math.max(t, 0); time += Math.max(t, 0);
const initiator = harEntry._request.initiator();
const exportedInitiator = {};
exportedInitiator.type = initiator.type;
if (initiator.url !== undefined)
exportedInitiator.url = initiator.url;
if (initiator.lineNumber !== undefined)
exportedInitiator.lineNumber = initiator.lineNumber;
if (initiator.stack)
exportedInitiator.stack = initiator.stack;
const entry = { const entry = {
startedDateTime: SDK.HARLog.pseudoWallTime(harEntry._request, harEntry._request.issueTime()).toJSON(), startedDateTime: SDK.HARLog.pseudoWallTime(harEntry._request, harEntry._request.issueTime()).toJSON(),
time: time, time: time,
...@@ -157,7 +167,9 @@ SDK.HARLog.Entry = class { ...@@ -157,7 +167,9 @@ SDK.HARLog.Entry = class {
cache: {}, // Not supported yet. cache: {}, // Not supported yet.
timings: timings, timings: timings,
// IPv6 address should not have square brackets per (https://tools.ietf.org/html/rfc2373#section-2.2). // IPv6 address should not have square brackets per (https://tools.ietf.org/html/rfc2373#section-2.2).
serverIPAddress: ipAddress.replace(/\[\]/g, '') serverIPAddress: ipAddress.replace(/\[\]/g, ''),
_initiator: exportedInitiator,
_priority: harEntry._request.priority()
}; };
// Chrome specific. // Chrome specific.
...@@ -403,4 +415,4 @@ SDK.HARLog.Entry = class { ...@@ -403,4 +415,4 @@ SDK.HARLog.Entry = class {
_blocked_queueing: number, _blocked_queueing: number,
_blocked_proxy: (number|undefined) _blocked_proxy: (number|undefined)
}} */ }} */
SDK.HARLog.Entry.Timing; SDK.HARLog.Entry.Timing;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment