[inspector] Skip sending data urls in the Runtime domain

This skips sending the data urls along with Runtime.CallFrame,
and Runtime.ExceptionDetails.

Also-by: bmeurer@chromium.org
Bug: chromium:1132260
Change-Id: I45136bc0d3217caf8fbd93946b021f56f64f04b9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2621077
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72063}
This commit is contained in:
Kim-Anh Tran 2021-01-11 14:57:14 +01:00 committed by Commit Bot
parent 8f6ecde0cd
commit 1e463205ea
4 changed files with 81 additions and 2 deletions

View File

@ -208,7 +208,12 @@ void V8ConsoleMessage::setLocation(const String16& url, unsigned lineNumber,
unsigned columnNumber,
std::unique_ptr<V8StackTraceImpl> stackTrace,
int scriptId) {
const char* dataURIPrefix = "data:";
if (url.substring(0, strlen(dataURIPrefix)) == dataURIPrefix) {
m_url = String16();
} else {
m_url = url;
}
m_lineNumber = lineNumber;
m_columnNumber = columnNumber;
m_stackTrace = std::move(stackTrace);

View File

@ -204,7 +204,12 @@ int StackFrame::columnNumber() const { return m_columnNumber; }
std::unique_ptr<protocol::Runtime::CallFrame> StackFrame::buildInspectorObject(
V8InspectorClient* client) const {
String16 frameUrl = m_sourceURL;
String16 frameUrl;
const char* dataURIPrefix = "data:";
if (m_sourceURL.substring(0, strlen(dataURIPrefix)) != dataURIPrefix) {
frameUrl = m_sourceURL;
}
if (client && !m_hasSourceURLComment && frameUrl.length() > 0) {
std::unique_ptr<StringBuffer> url =
client->resourceNameToUrl(toStringView(m_sourceURL));

View File

@ -0,0 +1,6 @@
Checks that we only send along non-data urls.
Test log with data uri.
console api called: Hello World!
callFrame: function test (url: )
callFrame: function (url: test.js)
exception details: Uncaught ReferenceError: Exception is not defined (url: )

View File

@ -0,0 +1,63 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that we only send along non-data urls.');
var expectedMessages = 2;
var messages = [];
Protocol.Runtime.enable();
Protocol.Console.enable();
Protocol.Runtime.onConsoleAPICalled(consoleAPICalled);
Protocol.Runtime.onExceptionThrown(exceptionThrown);
contextGroup.addScript(`
async function test() {
console.log("Hello World!");
throw new Exception("Exception thrown");
}
//# sourceURL=data:,pseudoDataUrl`);
function consoleAPICalled(result)
{
const msgText = result.params.args[0].value;
const callFrames = result.params.stackTrace.callFrames;
let messageParts = [];
messageParts.push(`console api called: ${msgText}`);
for (frame of callFrames) {
messageParts.push(` callFrame: function ${frame.functionName} (url: ${frame.url})`);
}
messages.push(messageParts.join("\n"));
if (!(--expectedMessages)) {
done();
}
}
function exceptionThrown(result)
{
const exceptionDetails = result.params.exceptionDetails;
const url = exceptionDetails.url;
const text = exceptionDetails.text;
messages.push(`exception details: ${text} (url: ${url ? url : ""})`)
if (!(--expectedMessages)) {
done();
}
}
function done()
{
messages.sort();
for (var message of messages) {
InspectorTest.log(message);
}
InspectorTest.completeTest();
}
(async function test() {
InspectorTest.log('Test log with data uri.');
await Protocol.Runtime.evaluate({ expression: `test()//# sourceURL=test.js`});
})();