Commit 31681456 authored by Patrick Brosset's avatar Patrick Brosset Committed by Commit Bot

CDP: Add column numbers to network initiator objects when possible

When initiator objects are created for parser and script type requests
a line number is passed, so that clients can possibly link http requests
to locations in source files.
For some reasons, only the line number is passed and not the column.
This means that for minified files (where all content is on one line) it
is impossible to link to the exact location.

Furthermore, clients like DevTools which know how to re-format minified
files won't be able to link to the right line once a file is
re-formatted.

The column number is already available in the TextPosition object that
is set in FetchInitiatorInfo, so in this change, we just return it to
the client too.

Corresponding frontend CL:
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2444236/

Bug: 1134064
Change-Id: I297924c3a22176309bd0fe4b613f7f1a42163ff6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442367Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Patrick Brosset <patrick.brosset@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#814138}
parent 8157f7c3
......@@ -4570,6 +4570,9 @@ domain Network
# Initiator line number, set for Parser type or for Script type (when script is importing
# module) (0-based).
optional number lineNumber
# Initiator column number, set for Parser type or for Script type (when script is importing
# module) (0-based).
optional number columnNumber
# Cookie object
type Cookie extends object
......
......@@ -1319,6 +1319,8 @@ InspectorNetworkAgent::BuildInitiatorObject(
initiator_object->setUrl(initiator_info.referrer);
initiator_object->setLineNumber(
initiator_info.position.line_.ZeroBasedInt());
initiator_object->setColumnNumber(
initiator_info.position.column_.ZeroBasedInt());
return initiator_object;
}
......@@ -1362,12 +1364,19 @@ InspectorNetworkAgent::BuildInitiatorObject(
.setType(protocol::Network::Initiator::TypeEnum::Parser)
.build();
initiator_object->setUrl(UrlWithoutFragment(document->Url()).GetString());
if (TextPosition::BelowRangePosition() != initiator_info.position)
if (TextPosition::BelowRangePosition() != initiator_info.position) {
initiator_object->setLineNumber(
initiator_info.position.line_.ZeroBasedInt());
else
initiator_object->setLineNumber(
document->GetScriptableDocumentParser()->LineNumber().ZeroBasedInt());
initiator_object->setColumnNumber(
initiator_info.position.column_.ZeroBasedInt());
} else {
initiator_object->setLineNumber(document->GetScriptableDocumentParser()
->GetTextPosition()
.line_.ZeroBasedInt());
initiator_object->setColumnNumber(document->GetScriptableDocumentParser()
->GetTextPosition()
.column_.ZeroBasedInt());
}
return initiator_object;
}
......
Tests resources initiator for images initiated by IMG tag, static CSS, CSS class added from JavaScript and XHR.
http://127.0.0.1:8000/devtools/network/resources/initiator.css: parser
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 2
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 2 60
http://127.0.0.1:8000/devtools/network/resources/resource.php?type=image&random=1&size=100: parser
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 4
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 4 53
http://127.0.0.1:8000/devtools/network/resources/resource.php?type=image&random=1&size=200: parser
http://127.0.0.1:8000/devtools/network/resources/initiator.css undefined
http://127.0.0.1:8000/devtools/network/resources/initiator.css undefined undefined
size=300 NOT FOUND
http://127.0.0.1:8000/devtools/network/resources/resource.php?type=image&random=1&size=400: script
loadData http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 13
loadData http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 13 8
http://127.0.0.1:8000/devtools/network/resources/style.css: parser
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 8
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 8 35
http://127.0.0.1:8000/devtools/network/resources/empty.html: parser
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 17
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 17 45
http://127.0.0.1:8000/devtools/network/resources/module1.js: script
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 19
http://127.0.0.1:8000/devtools/network/resources/network-initiator-frame.html 19 16
http://127.0.0.1:8000/devtools/network/resources/module2.js: script
http://127.0.0.1:8000/devtools/network/resources/module1.js 2
http://127.0.0.1:8000/devtools/network/resources/module1.js 2 20
http://127.0.0.1:8000/devtools/network/resources/example.ttf: parser
http://127.0.0.1:8000/devtools/network/resources/initiator.css undefined
http://127.0.0.1:8000/devtools/network/resources/initiator.css undefined undefined
......@@ -45,13 +45,13 @@
var initiator = request.initiator();
TestRunner.addResult(request.url() + ': ' + initiator.type);
if (initiator.url)
TestRunner.addResult(' ' + initiator.url + ' ' + initiator.lineNumber);
TestRunner.addResult(' ' + initiator.url + ' ' + initiator.lineNumber + ' ' + initiator.columnNumber);
if (initiator.stack) {
var stackTrace = initiator.stack;
for (var i = 0; i < stackTrace.callFrames.length; ++i) {
var frame = stackTrace.callFrames[i];
if (frame.lineNumber) {
TestRunner.addResult(' ' + frame.functionName + ' ' + frame.url + ' ' + frame.lineNumber);
TestRunner.addResult(' ' + frame.functionName + ' ' + frame.url + ' ' + frame.lineNumber + ' ' + frame.columnNumber);
break;
}
}
......
Tests that the initiator position is correct even when that initiator is minified.
http://127.0.0.1:8000/inspector-protocol/network/resources/abe.png
http://127.0.0.1:8000/inspector-protocol/network/resources/minified.html:0:154
http://127.0.0.1:8000/inspector-protocol/network/resources/module.js
http://127.0.0.1:8000/inspector-protocol/network/resources/minified.html:0:192
http://127.0.0.1:8000/inspector-protocol/network/resources/test.css
http://127.0.0.1:8000/inspector-protocol/network/resources/minified.html:0:107
(async function(testRunner) {
const {page, session, dp} = await testRunner.startBlank(
`Tests that the initiator position is correct even when that initiator is minified.`);
dp.Network.enable();
dp.Page.enable();
dp.Page.navigate({url: testRunner.url('resources/minified.html')});
let requests = [];
await dp.Network.onceRequestWillBeSent(e => {
requests.push(e.params);
// Wait for all expected requests to be done.
return requests.length === 4;
});
requests = requests.filter(r => !r.request.url.endsWith('minified.html'))
.sort((a, b) => a.request.url.localeCompare(b.request.url));
for (const {request, initiator} of requests) {
testRunner.log(request.url);
testRunner.log(` ${initiator.url}:${initiator.lineNumber}:${initiator.columnNumber}`);
}
testRunner.completeTest();
})
<!DOCTYPE html><html><head><meta charset="utf-8"><title>test</title><link rel="stylesheet" href="test.css"></head><body>Hello world<br><img src="abe.png"><script type="module">import {x} from "./module.js";</script></body></html>
\ 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