[DevTools] Do not report worker console messages twice

When the worker is still alive while DevTools is being opened,
there is a race between console messages coming from page and
worker target creation.

Bug: 908863
Change-Id: I9495d4becada0e4f2bd208c0922b2a2a3ea98af9
Reviewed-on: https://chromium-review.googlesource.com/c/1359039
Reviewed-by: Joel Einbinder <einbinder@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614609}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e41224229e7a61deb59a2a5d7bf5175cc56bf14c
This commit is contained in:
Dmitry Gozman
2018-12-07 04:46:27 +00:00
committed by Commit Bot
parent d982f6cdf8
commit e58f6af1c6
2 changed files with 16 additions and 4 deletions
+16 -1
View File
@@ -42,7 +42,22 @@ BrowserSDK.LogManager = class {
if (data.entry.networkRequestId)
SDK.networkLog.associateConsoleMessageWithRequest(consoleMessage, data.entry.networkRequestId);
SDK.consoleModel.addMessage(consoleMessage);
if (consoleMessage.source === SDK.ConsoleMessage.MessageSource.Worker) {
const workerId = consoleMessage.workerId || '';
// We have a copy of worker messages reported through the page, so that
// user can see messages from the worker which has been already destroyed.
// When opening DevTools, give us some time to connect to the worker and
// not report the message twice if the worker is still alive.
if (SDK.targetManager.targetById(workerId))
return;
setTimeout(() => {
if (!SDK.targetManager.targetById(workerId))
SDK.consoleModel.addMessage(consoleMessage);
}, 1000);
} else {
SDK.consoleModel.addMessage(consoleMessage);
}
}
};
-3
View File
@@ -159,9 +159,6 @@ SDK.ConsoleModel = class extends Common.Object {
* @param {!SDK.ConsoleMessage} msg
*/
addMessage(msg) {
if (msg.source === SDK.ConsoleMessage.MessageSource.Worker && SDK.targetManager.targetById(msg.workerId))
return;
msg._pageLoadSequenceNumber = this._pageLoadSequenceNumber;
if (msg.source === SDK.ConsoleMessage.MessageSource.ConsoleAPI && msg.type === SDK.ConsoleMessage.MessageType.Clear)
this._clearIfNecessary();