Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 5 | /* |
| 6 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 7 | * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 8 | * Copyright (C) 2009 Joseph Pecoraro |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 20 | * its contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 24 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 34 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 35 | /* eslint-disable rulesdir/no_underscored_properties */ |
| 36 | |
Tim van der Lippe | 7696157 | 2021-04-06 10:48:07 | [diff] [blame] | 37 | import * as Common from '../../core/common/common.js'; |
Tim van der Lippe | bb352e6 | 2021-04-01 17:57:28 | [diff] [blame] | 38 | import * as i18n from '../../core/i18n/i18n.js'; |
Tim van der Lippe | aa1ed7a | 2021-03-31 14:38:27 | [diff] [blame] | 39 | import * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | e00b92f | 2021-03-31 16:52:17 | [diff] [blame] | 40 | import * as SDK from '../../core/sdk/sdk.js'; |
Tim van der Lippe | 229a54f | 2021-05-14 16:59:05 | [diff] [blame] | 41 | import * as Protocol from '../../generated/protocol.js'; |
Tim van der Lippe | 959b6f0 | 2021-04-07 09:07:59 | [diff] [blame] | 42 | import * as Bindings from '../../models/bindings/bindings.js'; |
Sigurd Schneider | cf5b830 | 2021-04-23 07:52:27 | [diff] [blame] | 43 | import * as Logs from '../../models/logs/logs.js'; |
Tim van der Lippe | fca98ed | 2021-04-08 14:10:14 | [diff] [blame] | 44 | import * as TextUtils from '../../models/text_utils/text_utils.js'; |
Tim van der Lippe | 99aeaf3 | 2021-04-09 10:33:34 | [diff] [blame] | 45 | import * as Workspace from '../../models/workspace/workspace.js'; |
Tim van der Lippe | 8499fe2 | 2021-04-12 16:42:47 | [diff] [blame] | 46 | import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js'; |
Tim van der Lippe | 0dd7a05 | 2021-04-12 16:44:23 | [diff] [blame] | 47 | import * as ObjectUI from '../../ui/legacy/components/object_ui/object_ui.js'; |
Tim van der Lippe | 9a1c973 | 2021-04-14 14:14:07 | [diff] [blame] | 48 | import * as TextEditor from '../../ui/legacy/components/text_editor/text_editor.js'; |
Tim van der Lippe | 339ad26 | 2021-04-21 12:23:36 | [diff] [blame] | 49 | import * as Components from '../../ui/legacy/components/utils/utils.js'; |
Tim van der Lippe | aa61faf | 2021-04-07 15:32:07 | [diff] [blame] | 50 | import * as UI from '../../ui/legacy/legacy.js'; |
Tim van der Lippe | fddcf40 | 2021-04-19 13:00:29 | [diff] [blame] | 51 | import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 52 | |
Tim van der Lippe | bfbb58f | 2021-02-25 17:34:19 | [diff] [blame] | 53 | import type {ConsoleViewportElement} from './ConsoleViewport.js'; |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 54 | |
Simon Zünd | fbfd107 | 2021-03-01 07:38:53 | [diff] [blame] | 55 | const UIStrings = { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 56 | /** |
Peter Marshall | f295a4b | 2021-02-26 09:48:03 | [diff] [blame] | 57 | * @description Message element text content in Console View Message of the Console panel. Shown |
| 58 | * when the user tried to run console.clear() but the 'Preserve log' option is enabled, which stops |
| 59 | * the log from being cleared. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 60 | */ |
| 61 | consoleclearWasPreventedDueTo: '`console.clear()` was prevented due to \'Preserve log\'', |
| 62 | /** |
Peter Marshall | b8bd00f | 2021-02-24 08:25:18 | [diff] [blame] | 63 | * @description Text shown in the Console panel after the user has cleared the console, which |
| 64 | * removes all messages from the console so that it is empty. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 65 | */ |
| 66 | consoleWasCleared: 'Console was cleared', |
| 67 | /** |
| 68 | *@description Message element title in Console View Message of the Console panel |
| 69 | *@example {Ctrl+L} PH1 |
| 70 | */ |
| 71 | clearAllMessagesWithS: 'Clear all messages with {PH1}', |
| 72 | /** |
| 73 | *@description Message prefix in Console View Message of the Console panel |
| 74 | */ |
| 75 | assertionFailed: 'Assertion failed: ', |
| 76 | /** |
| 77 | *@description Message text in Console View Message of the Console panel |
| 78 | *@example {console.log(1)} PH1 |
| 79 | */ |
Peter Marshall | 40dd7d9 | 2021-02-19 11:07:37 | [diff] [blame] | 80 | violationS: '`[Violation]` {PH1}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 81 | /** |
| 82 | *@description Message text in Console View Message of the Console panel |
| 83 | *@example {console.log(1)} PH1 |
| 84 | */ |
Peter Marshall | 40dd7d9 | 2021-02-19 11:07:37 | [diff] [blame] | 85 | interventionS: '`[Intervention]` {PH1}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 86 | /** |
| 87 | *@description Message text in Console View Message of the Console panel |
| 88 | *@example {console.log(1)} PH1 |
| 89 | */ |
Peter Marshall | 40dd7d9 | 2021-02-19 11:07:37 | [diff] [blame] | 90 | deprecationS: '`[Deprecation]` {PH1}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 91 | /** |
| 92 | *@description Note title in Console View Message of the Console panel |
| 93 | */ |
| 94 | thisValueWillNotBeCollectedUntil: 'This value will not be collected until console is cleared.', |
| 95 | /** |
| 96 | *@description Note title in Console View Message of the Console panel |
| 97 | */ |
| 98 | thisValueWasEvaluatedUponFirst: 'This value was evaluated upon first expanding. It may have changed since then.', |
| 99 | /** |
| 100 | *@description Note title in Console View Message of the Console panel |
| 101 | */ |
| 102 | functionWasResolvedFromBound: 'Function was resolved from bound function.', |
| 103 | /** |
Peter Marshall | f625dc8 | 2021-03-02 08:10:57 | [diff] [blame] | 104 | * @description Shown in the Console panel when an exception is thrown when trying to access a |
| 105 | * property on an object. Should be translated. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 106 | */ |
| 107 | exception: '<exception>', |
| 108 | /** |
| 109 | *@description Text to indicate an item is a warning |
| 110 | */ |
| 111 | warning: 'Warning', |
| 112 | /** |
| 113 | *@description Text for errors |
| 114 | */ |
| 115 | error: 'Error', |
| 116 | /** |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 117 | * @description Announced by the screen reader to indicate how many times a particular message in |
| 118 | * the console was repeated. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 119 | */ |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 120 | repeatS: '{n, plural, =1 {Repeated # time} other {Repeated # times}}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 121 | /** |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 122 | * @description Announced by the screen reader to indicate how many times a particular warning |
| 123 | * message in the console was repeated. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 124 | */ |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 125 | warningS: '{n, plural, =1 {Warning, Repeated # time} other {Warning, Repeated # times}}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 126 | /** |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 127 | * @description Announced by the screen reader to indicate how many times a particular error |
| 128 | * message in the console was repeated. |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 129 | */ |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 130 | errorS: '{n, plural, =1 {Error, Repeated # time} other {Error, Repeated # times}}', |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 131 | /** |
Tim van der Lippe | e4b96c6 | 2021-02-17 12:43:16 | [diff] [blame] | 132 | *@description Text appended to grouped console messages that are related to URL requests |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 133 | */ |
| 134 | url: '<URL>', |
| 135 | /** |
Tim van der Lippe | e4b96c6 | 2021-02-17 12:43:16 | [diff] [blame] | 136 | *@description Text appended to grouped console messages about tasks that took longer than N ms |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 137 | */ |
| 138 | tookNms: 'took <N>ms', |
| 139 | /** |
Tim van der Lippe | e4b96c6 | 2021-02-17 12:43:16 | [diff] [blame] | 140 | *@description Text appended to grouped console messages about tasks that are related to some DOM event |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 141 | */ |
| 142 | someEvent: '<some> event', |
| 143 | /** |
Tim van der Lippe | e4b96c6 | 2021-02-17 12:43:16 | [diff] [blame] | 144 | *@description Text appended to grouped console messages about tasks that are related to a particular milestone |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 145 | */ |
| 146 | Mxx: ' M<XX>', |
| 147 | /** |
Tim van der Lippe | e4b96c6 | 2021-02-17 12:43:16 | [diff] [blame] | 148 | *@description Text appended to grouped console messages about tasks that are related to autofill completions |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 149 | */ |
| 150 | attribute: '<attribute>', |
| 151 | /** |
| 152 | *@description Text for the index of something |
| 153 | */ |
| 154 | index: '(index)', |
| 155 | /** |
| 156 | *@description Text for the value of something |
| 157 | */ |
| 158 | value: 'Value', |
| 159 | /** |
| 160 | *@description Title of the Console tool |
| 161 | */ |
| 162 | console: 'Console', |
| 163 | }; |
Tim van der Lippe | 586c802 | 2021-03-18 15:18:20 | [diff] [blame] | 164 | const str_ = i18n.i18n.registerUIStrings('panels/console/ConsoleViewMessage.ts', UIStrings); |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 165 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 166 | const elementToMessage = new WeakMap<Element, ConsoleViewMessage>(); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 167 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 168 | export const getMessageForElement = (element: Element): ConsoleViewMessage|undefined => { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 169 | return elementToMessage.get(element); |
| 170 | }; |
| 171 | |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 172 | // This value reflects the 18px min-height of .console-message, plus the |
| 173 | // 1px border of .console-message-wrapper. Keep in sync with consoleView.css. |
| 174 | const defaultConsoleRowHeight = 19; |
| 175 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 176 | const parameterToRemoteObject = (runtimeModel: SDK.RuntimeModel.RuntimeModel|null): ( |
| 177 | parameter?: SDK.RemoteObject.RemoteObject|Protocol.Runtime.RemoteObject|string) => SDK.RemoteObject.RemoteObject => |
| 178 | (parameter?: string|SDK.RemoteObject.RemoteObject|Protocol.Runtime.RemoteObject): SDK.RemoteObject.RemoteObject => { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 179 | if (parameter instanceof SDK.RemoteObject.RemoteObject) { |
| 180 | return parameter; |
| 181 | } |
| 182 | if (!runtimeModel) { |
| 183 | return SDK.RemoteObject.RemoteObject.fromLocalObject(parameter); |
| 184 | } |
| 185 | if (typeof parameter === 'object') { |
| 186 | return runtimeModel.createRemoteObject(parameter); |
| 187 | } |
| 188 | return runtimeModel.createRemoteObjectFromPrimitiveValue(parameter); |
| 189 | }; |
| 190 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 191 | export class ConsoleViewMessage implements ConsoleViewportElement { |
| 192 | _message: SDK.ConsoleModel.ConsoleMessage; |
| 193 | _linkifier: Components.Linkifier.Linkifier; |
| 194 | _repeatCount: number; |
| 195 | _closeGroupDecorationCount: number; |
| 196 | _nestingLevel: number; |
| 197 | _selectableChildren: { |
| 198 | element: HTMLElement, |
| 199 | forceSelect: () => void, |
| 200 | }[]; |
| 201 | _messageResized: (arg0: Common.EventTarget.EventTargetEvent) => void; |
| 202 | _element: HTMLElement|null; |
| 203 | _previewFormatter: ObjectUI.RemoteObjectPreviewFormatter.RemoteObjectPreviewFormatter; |
| 204 | _searchRegex: RegExp|null; |
| 205 | _messageLevelIcon: UI.Icon.Icon|null; |
| 206 | _traceExpanded: boolean; |
| 207 | _expandTrace: ((arg0: boolean) => void)|null; |
| 208 | _anchorElement: HTMLElement|null; |
| 209 | _contentElement: HTMLElement|null; |
| 210 | _nestingLevelMarkers: HTMLElement[]|null; |
| 211 | _searchHighlightNodes: Element[]; |
| 212 | _searchHighlightNodeChanges: UI.UIUtils.HighlightChange[]; |
| 213 | _isVisible: boolean; |
| 214 | _cachedHeight: number; |
| 215 | _messagePrefix: string; |
| 216 | _timestampElement: HTMLElement|null; |
| 217 | _inSimilarGroup: boolean; |
| 218 | _similarGroupMarker: HTMLElement|null; |
| 219 | _lastInSimilarGroup: boolean; |
| 220 | _groupKey: string; |
| 221 | _repeatCountElement: UI.UIUtils.DevToolsSmallBubble|null; |
| 222 | |
| 223 | constructor( |
| 224 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 225 | onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 226 | this._message = consoleMessage; |
| 227 | this._linkifier = linkifier; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 228 | this._repeatCount = 1; |
| 229 | this._closeGroupDecorationCount = 0; |
| 230 | this._nestingLevel = nestingLevel; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 231 | this._selectableChildren = []; |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 232 | this._messageResized = onResize; |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 233 | this._element = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 235 | this._previewFormatter = new ObjectUI.RemoteObjectPreviewFormatter.RemoteObjectPreviewFormatter(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 236 | this._searchRegex = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | this._messageLevelIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 238 | this._traceExpanded = false; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 239 | this._expandTrace = null; |
John Emau | bb2897a | 2019-10-04 17:37:32 | [diff] [blame] | 240 | this._anchorElement = null; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 241 | this._contentElement = null; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 242 | this._nestingLevelMarkers = null; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 243 | this._searchHighlightNodes = []; |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 244 | this._searchHighlightNodeChanges = []; |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 245 | this._isVisible = false; |
| 246 | this._cachedHeight = 0; |
| 247 | this._messagePrefix = ''; |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 248 | this._timestampElement = null; |
| 249 | this._inSimilarGroup = false; |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 250 | this._similarGroupMarker = null; |
| 251 | this._lastInSimilarGroup = false; |
| 252 | this._groupKey = ''; |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 253 | this._repeatCountElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 254 | } |
| 255 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 256 | element(): HTMLElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 257 | return this.toMessageElement(); |
| 258 | } |
| 259 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 260 | wasShown(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 261 | this._isVisible = true; |
| 262 | } |
| 263 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 264 | onResize(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 265 | } |
| 266 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 267 | willHide(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | this._isVisible = false; |
Erik Luo | 4b00232 | 2018-07-30 21:23:31 | [diff] [blame] | 269 | this._cachedHeight = this.element().offsetHeight; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 270 | } |
| 271 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 272 | isVisible(): boolean { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 273 | return this._isVisible; |
| 274 | } |
| 275 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 276 | fastHeight(): number { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 277 | if (this._cachedHeight) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 278 | return this._cachedHeight; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 279 | } |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 280 | return this.approximateFastHeight(); |
| 281 | } |
| 282 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 283 | approximateFastHeight(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 284 | return defaultConsoleRowHeight; |
| 285 | } |
| 286 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 287 | consoleMessage(): SDK.ConsoleModel.ConsoleMessage { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 288 | return this._message; |
| 289 | } |
| 290 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 291 | _buildMessage(): HTMLElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 292 | let messageElement; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 293 | let messageText: Common.UIString.LocalizedString|string = this._message.messageText; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 294 | if (this._message.source === SDK.ConsoleModel.FrontendMessageSource.ConsoleAPI) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | switch (this._message.type) { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 296 | case Protocol.Runtime.ConsoleAPICalledEventType.Trace: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 297 | messageElement = this._format(this._message.parameters || ['console.trace']); |
| 298 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 299 | case Protocol.Runtime.ConsoleAPICalledEventType.Clear: |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 300 | messageElement = document.createElement('span'); |
| 301 | messageElement.classList.add('console-info'); |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 302 | if (Common.Settings.Settings.instance().moduleSetting('preserveConsoleLog').get()) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 303 | messageElement.textContent = i18nString(UIStrings.consoleclearWasPreventedDueTo); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 304 | } else { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 305 | messageElement.textContent = i18nString(UIStrings.consoleWasCleared); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 306 | } |
Tim van der Lippe | 420e5e3 | 2020-11-23 16:58:46 | [diff] [blame] | 307 | UI.Tooltip.Tooltip.install( |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 308 | messageElement, i18nString(UIStrings.clearAllMessagesWithS, { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 309 | PH1: UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('console.clear'), |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 310 | })); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 311 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 312 | case Protocol.Runtime.ConsoleAPICalledEventType.Dir: { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 313 | const obj = this._message.parameters ? this._message.parameters[0] : undefined; |
| 314 | const args = ['%O', obj]; |
| 315 | messageElement = this._format(args); |
| 316 | break; |
| 317 | } |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 318 | case Protocol.Runtime.ConsoleAPICalledEventType.Profile: |
| 319 | case Protocol.Runtime.ConsoleAPICalledEventType.ProfileEnd: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 320 | messageElement = this._format([messageText]); |
| 321 | break; |
| 322 | default: { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 323 | if (this._message.type === Protocol.Runtime.ConsoleAPICalledEventType.Assert) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 324 | this._messagePrefix = i18nString(UIStrings.assertionFailed); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 325 | } |
| 326 | if (this._message.parameters && this._message.parameters.length === 1) { |
| 327 | const parameter = this._message.parameters[0]; |
| 328 | if (typeof parameter !== 'string' && parameter.type === 'string') { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 329 | messageElement = this._tryFormatAsError((parameter.value as string)); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 330 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 331 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 332 | const args = this._message.parameters || [messageText]; |
| 333 | messageElement = messageElement || this._format(args); |
| 334 | } |
| 335 | } |
| 336 | } else { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 337 | if (this._message.source === Protocol.Log.LogEntrySource.Network) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 338 | messageElement = this._formatAsNetworkRequest() || this._format([messageText]); |
| 339 | } else { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 340 | const messageInParameters = this._message.parameters && messageText === (this._message.parameters[0] as string); |
Peter Marshall | 40dd7d9 | 2021-02-19 11:07:37 | [diff] [blame] | 341 | // These terms are locked because the console message will not be translated anyway. |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 342 | if (this._message.source === Protocol.Log.LogEntrySource.Violation) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 343 | messageText = i18nString(UIStrings.violationS, {PH1: messageText}); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 344 | } else if (this._message.source === Protocol.Log.LogEntrySource.Intervention) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 345 | messageText = i18nString(UIStrings.interventionS, {PH1: messageText}); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 346 | } else if (this._message.source === Protocol.Log.LogEntrySource.Deprecation) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 347 | messageText = i18nString(UIStrings.deprecationS, {PH1: messageText}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 348 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 349 | const args = this._message.parameters || [messageText]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 350 | if (messageInParameters) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 351 | args[0] = messageText; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 352 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 353 | messageElement = this._format(args); |
| 354 | } |
| 355 | } |
| 356 | messageElement.classList.add('console-message-text'); |
| 357 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 358 | const formattedMessage = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 359 | formattedMessage.classList.add('source-code'); |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 360 | this._anchorElement = this._buildMessageAnchor(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 361 | if (this._anchorElement) { |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 362 | formattedMessage.appendChild(this._anchorElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 363 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 364 | formattedMessage.appendChild(messageElement); |
| 365 | return formattedMessage; |
| 366 | } |
| 367 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 368 | _formatAsNetworkRequest(): HTMLElement|null { |
Sigurd Schneider | cf5b830 | 2021-04-23 07:52:27 | [diff] [blame] | 369 | const request = Logs.NetworkLog.NetworkLog.requestForConsoleMessage(this._message); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 370 | if (!request) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 371 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 372 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 373 | const messageElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 374 | if (this._message.level === Protocol.Log.LogEntryLevel.Error) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 375 | UI.UIUtils.createTextChild(messageElement, request.requestMethod + ' '); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 376 | const linkElement = Components.Linkifier.Linkifier.linkifyRevealable(request, request.url(), request.url()); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 377 | // Focus is handled by the viewport. |
| 378 | linkElement.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 379 | this._selectableChildren.push({element: linkElement, forceSelect: (): void => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 380 | messageElement.appendChild(linkElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 381 | if (request.failed) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 382 | UI.UIUtils.createTextChildren(messageElement, ' ', request.localizedFailDescription || ''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 383 | } |
| 384 | if (request.statusCode !== 0) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 385 | UI.UIUtils.createTextChildren(messageElement, ' ', String(request.statusCode)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 386 | } |
| 387 | if (request.statusText) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 388 | UI.UIUtils.createTextChildren(messageElement, ' (', request.statusText, ')'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 389 | } |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 390 | } else { |
Erik Luo | ad5f394 | 2019-03-26 20:53:44 | [diff] [blame] | 391 | const messageText = this._message.messageText; |
| 392 | const fragment = this._linkifyWithCustomLinkifier(messageText, (text, url, lineNumber, columnNumber) => { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 393 | const linkElement = url === request.url() ? |
| 394 | Components.Linkifier.Linkifier.linkifyRevealable( |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 395 | (request as SDK.NetworkRequest.NetworkRequest), url, request.url()) : |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 396 | Components.Linkifier.Linkifier.linkifyURL( |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 397 | url, ({text, lineNumber, columnNumber} as Components.Linkifier.LinkifyURLOptions)); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 398 | linkElement.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 399 | this._selectableChildren.push({element: linkElement, forceSelect: (): void => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 400 | return linkElement; |
| 401 | }); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 402 | messageElement.appendChild(fragment); |
| 403 | } |
| 404 | return messageElement; |
| 405 | } |
| 406 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 407 | _buildMessageAnchor(): HTMLElement|null { |
| 408 | const linkify = (message: SDK.ConsoleModel.ConsoleMessage): HTMLElement|null => { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 409 | if (message.scriptId) { |
| 410 | return this._linkifyScriptId(message.scriptId, message.url || '', message.line, message.column); |
| 411 | } |
| 412 | if (message.stackTrace && message.stackTrace.callFrames.length) { |
| 413 | return this._linkifyStackTraceTopFrame(message.stackTrace); |
| 414 | } |
| 415 | if (message.url && message.url !== 'undefined') { |
| 416 | return this._linkifyLocation(message.url, message.line, message.column); |
| 417 | } |
| 418 | return null; |
| 419 | }; |
| 420 | const anchorElement = linkify(this._message); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 421 | // Append a space to prevent the anchor text from being glued to the console message when the user selects and copies the console messages. |
| 422 | if (anchorElement) { |
John Emau | f7e30fb | 2019-10-04 19:12:32 | [diff] [blame] | 423 | anchorElement.tabIndex = -1; |
| 424 | this._selectableChildren.push({ |
| 425 | element: anchorElement, |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 426 | forceSelect: (): void => anchorElement.focus(), |
John Emau | f7e30fb | 2019-10-04 19:12:32 | [diff] [blame] | 427 | }); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 428 | const anchorWrapperElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 429 | anchorWrapperElement.classList.add('console-message-anchor'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 430 | anchorWrapperElement.appendChild(anchorElement); |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 431 | UI.UIUtils.createTextChild(anchorWrapperElement, ' '); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 432 | return anchorWrapperElement; |
| 433 | } |
| 434 | return null; |
| 435 | } |
| 436 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 437 | _buildMessageWithStackTrace(runtimeModel: SDK.RuntimeModel.RuntimeModel): HTMLElement { |
| 438 | const toggleElement = (document.createElement('div') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 439 | toggleElement.classList.add('console-message-stack-trace-toggle'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 440 | const contentElement = toggleElement.createChild('div', 'console-message-stack-trace-wrapper'); |
Brandon Walderman | a004e2a | 2021-04-06 18:41:59 | [diff] [blame] | 441 | UI.ARIAUtils.markAsTree(contentElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 442 | |
| 443 | const messageElement = this._buildMessage(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 444 | const icon = UI.Icon.Icon.create('smallicon-triangle-right', 'console-message-expand-icon'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 445 | const clickableElement = contentElement.createChild('div'); |
Brandon Walderman | a004e2a | 2021-04-06 18:41:59 | [diff] [blame] | 446 | UI.ARIAUtils.markAsTreeitem(clickableElement); |
| 447 | UI.ARIAUtils.setExpanded(clickableElement, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 448 | clickableElement.appendChild(icon); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 449 | // Intercept focus to avoid highlight on click. |
| 450 | clickableElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 451 | clickableElement.appendChild(messageElement); |
| 452 | const stackTraceElement = contentElement.createChild('div'); |
| 453 | const stackTracePreview = Components.JSPresentationUtils.buildStackTracePreviewContents( |
Wolfgang Beyer | 08261c7 | 2021-03-09 09:21:34 | [diff] [blame] | 454 | runtimeModel.target(), this._linkifier, {stackTrace: this._message.stackTrace, tabStops: undefined}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 455 | stackTraceElement.appendChild(stackTracePreview.element); |
| 456 | for (const linkElement of stackTracePreview.links) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 457 | this._selectableChildren.push({element: linkElement, forceSelect: (): void => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 458 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 459 | stackTraceElement.classList.add('hidden'); |
Brandon Walderman | a004e2a | 2021-04-06 18:41:59 | [diff] [blame] | 460 | UI.ARIAUtils.markAsGroup(stackTraceElement); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 461 | this._expandTrace = (expand: boolean): void => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 462 | icon.setIconType(expand ? 'smallicon-triangle-down' : 'smallicon-triangle-right'); |
| 463 | stackTraceElement.classList.toggle('hidden', !expand); |
Brandon Walderman | a004e2a | 2021-04-06 18:41:59 | [diff] [blame] | 464 | UI.ARIAUtils.setExpanded(clickableElement, expand); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 465 | this._traceExpanded = expand; |
| 466 | }; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 467 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 468 | const toggleStackTrace = (event: Event): void => { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 469 | if (UI.UIUtils.isEditing() || contentElement.hasSelection()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 470 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 471 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 472 | this._expandTrace && this._expandTrace(stackTraceElement.classList.contains('hidden')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 473 | event.consume(); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 474 | }; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 475 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 476 | clickableElement.addEventListener('click', toggleStackTrace, false); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 477 | if (this._message.type === Protocol.Runtime.ConsoleAPICalledEventType.Trace) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 478 | this._expandTrace(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 479 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 480 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 481 | // @ts-ignore |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 482 | toggleElement._expandStackTraceForTest = this._expandTrace.bind(this, true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | return toggleElement; |
| 484 | } |
| 485 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 486 | _linkifyLocation(url: string, lineNumber: number, columnNumber: number): HTMLElement|null { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 487 | const runtimeModel = this._message.runtimeModel(); |
| 488 | if (!runtimeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 489 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 490 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 491 | return this._linkifier.linkifyScriptLocation( |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 492 | runtimeModel.target(), /* scriptId */ null, url, lineNumber, |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 493 | {columnNumber, className: undefined, tabStop: undefined, inlineFrameIndex: 0}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 494 | } |
| 495 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 496 | _linkifyStackTraceTopFrame(stackTrace: Protocol.Runtime.StackTrace): HTMLElement|null { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 497 | const runtimeModel = this._message.runtimeModel(); |
| 498 | if (!runtimeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 499 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 500 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 501 | return this._linkifier.linkifyStackTraceTopFrame(runtimeModel.target(), stackTrace); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | } |
| 503 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 504 | _linkifyScriptId(scriptId: string, url: string, lineNumber: number, columnNumber: number): HTMLElement|null { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 505 | const runtimeModel = this._message.runtimeModel(); |
| 506 | if (!runtimeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 507 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 508 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 509 | return this._linkifier.linkifyScriptLocation( |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 510 | runtimeModel.target(), scriptId, url, lineNumber, |
| 511 | {columnNumber, className: undefined, tabStop: undefined, inlineFrameIndex: 0}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 512 | } |
| 513 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 514 | _format(rawParameters: (string|SDK.RemoteObject.RemoteObject|Protocol.Runtime.RemoteObject|undefined)[]): |
| 515 | HTMLElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 516 | // This node is used like a Builder. Values are continually appended onto it. |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 517 | const formattedResult = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 518 | if (this._messagePrefix) { |
Pavel Feldman | 9f0f0a3 | 2018-12-18 02:09:13 | [diff] [blame] | 519 | formattedResult.createChild('span').textContent = this._messagePrefix; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 520 | } |
| 521 | if (!rawParameters.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 522 | return formattedResult; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 523 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 524 | |
| 525 | // Formatting code below assumes that parameters are all wrappers whereas frontend console |
| 526 | // API allows passing arbitrary values as messages (strings, numbers, etc.). Wrap them here. |
| 527 | // FIXME: Only pass runtime wrappers here. |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 528 | let parameters = rawParameters.map(parameterToRemoteObject(this._message.runtimeModel())); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 529 | |
| 530 | // There can be string log and string eval result. We distinguish between them based on message type. |
| 531 | const shouldFormatMessage = |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 532 | SDK.RemoteObject.RemoteObject.type((parameters as SDK.RemoteObject.RemoteObject[])[0]) === 'string' && |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 533 | (this._message.type !== SDK.ConsoleModel.FrontendMessageType.Result || |
| 534 | this._message.level === Protocol.Log.LogEntryLevel.Error); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 535 | |
| 536 | // Multiple parameters with the first being a format string. Save unused substitutions. |
| 537 | if (shouldFormatMessage) { |
| 538 | const result = this._formatWithSubstitutionString( |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 539 | (parameters[0].description as string), parameters.slice(1), formattedResult); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 540 | parameters = Array.from(result.unusedSubstitutions || []); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 541 | if (parameters.length) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 542 | UI.UIUtils.createTextChild(formattedResult, ' '); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 543 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | // Single parameter, or unused substitutions from above. |
| 547 | for (let i = 0; i < parameters.length; ++i) { |
| 548 | // Inline strings when formatting. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 549 | if (shouldFormatMessage && parameters[i].type === 'string') { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 550 | formattedResult.appendChild(this._linkifyStringAsFragment(parameters[i].description || '')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 551 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 552 | formattedResult.appendChild(this._formatParameter(parameters[i], false, true)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 553 | } |
| 554 | if (i < parameters.length - 1) { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 555 | UI.UIUtils.createTextChild(formattedResult, ' '); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 556 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 557 | } |
| 558 | return formattedResult; |
| 559 | } |
| 560 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 561 | _formatParameter(output: SDK.RemoteObject.RemoteObject, forceObjectFormat?: boolean, includePreview?: boolean): |
| 562 | HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 563 | if (output.customPreview()) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 564 | return new ObjectUI.CustomPreviewComponent.CustomPreviewComponent(output).element as HTMLElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 565 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 566 | |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 567 | const outputType = forceObjectFormat ? 'object' : (output.subtype || output.type); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 568 | let element; |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 569 | switch (outputType) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 570 | case 'error': |
| 571 | element = this._formatParameterAsError(output); |
| 572 | break; |
| 573 | case 'function': |
| 574 | element = this._formatParameterAsFunction(output, includePreview); |
| 575 | break; |
| 576 | case 'array': |
| 577 | case 'arraybuffer': |
| 578 | case 'blob': |
| 579 | case 'dataview': |
| 580 | case 'generator': |
| 581 | case 'iterator': |
| 582 | case 'map': |
| 583 | case 'object': |
| 584 | case 'promise': |
| 585 | case 'proxy': |
| 586 | case 'set': |
| 587 | case 'typedarray': |
Benedikt Meurer | 5658dd2 | 2021-03-18 09:37:23 | [diff] [blame] | 588 | case 'wasmvalue': |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 589 | case 'weakmap': |
| 590 | case 'weakset': |
Benedikt Meurer | dead315 | 2020-12-07 08:43:40 | [diff] [blame] | 591 | case 'webassemblymemory': |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 592 | element = this._formatParameterAsObject(output, includePreview); |
| 593 | break; |
| 594 | case 'node': |
| 595 | element = output.isNode() ? this._formatParameterAsNode(output) : this._formatParameterAsObject(output, false); |
| 596 | break; |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 597 | case 'trustedtype': |
| 598 | element = this._formatParameterAsObject(output, false); |
| 599 | break; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 600 | case 'string': |
| 601 | element = this._formatParameterAsString(output); |
| 602 | break; |
| 603 | case 'boolean': |
| 604 | case 'date': |
| 605 | case 'null': |
| 606 | case 'number': |
| 607 | case 'regexp': |
| 608 | case 'symbol': |
| 609 | case 'undefined': |
| 610 | case 'bigint': |
| 611 | element = this._formatParameterAsValue(output); |
| 612 | break; |
| 613 | default: |
| 614 | element = this._formatParameterAsValue(output); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 615 | console.error(`Tried to format remote object of unknown type ${outputType}.`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 616 | } |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 617 | element.classList.add(`object-value-${outputType}`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 618 | element.classList.add('source-code'); |
| 619 | return element; |
| 620 | } |
| 621 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 622 | _formatParameterAsValue(obj: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 623 | const result = (document.createElement('span') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 624 | const description = obj.description || ''; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 625 | if (description.length > getMaxTokenizableStringLength()) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 626 | const propertyValue = new ObjectUI.ObjectPropertiesSection.ExpandableTextPropertyValue( |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 627 | document.createElement('span'), description, getLongStringVisibleLength()); |
Connor Moody | 1a5c0d3 | 2019-12-19 07:23:36 | [diff] [blame] | 628 | result.appendChild(propertyValue.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 629 | } else { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 630 | UI.UIUtils.createTextChild(result, description); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 631 | } |
| 632 | if (obj.objectId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 633 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, obj), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 634 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 635 | return result; |
| 636 | } |
| 637 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 638 | _formatParameterAsTrustedType(obj: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 639 | const result = (document.createElement('span') as HTMLElement); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 640 | const trustedContentSpan = document.createElement('span'); |
| 641 | trustedContentSpan.appendChild(this._formatParameterAsString(obj)); |
| 642 | trustedContentSpan.classList.add('object-value-string'); |
Alfonso Castaño | dfe8ca3 | 2020-10-29 13:03:09 | [diff] [blame] | 643 | UI.UIUtils.createTextChild(result, `${obj.className} `); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 644 | result.appendChild(trustedContentSpan); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 645 | return result; |
| 646 | } |
| 647 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 648 | _formatParameterAsObject(obj: SDK.RemoteObject.RemoteObject, includePreview?: boolean): HTMLElement { |
| 649 | const titleElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 650 | titleElement.classList.add('console-object'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 651 | if (includePreview && obj.preview) { |
| 652 | titleElement.classList.add('console-object-preview'); |
| 653 | this._previewFormatter.appendObjectPreview(titleElement, obj.preview, false /* isEntry */); |
| 654 | } else if (obj.type === 'function') { |
| 655 | const functionElement = titleElement.createChild('span'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 656 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.formatObjectAsFunction(obj, functionElement, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 657 | titleElement.classList.add('object-value-function'); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 658 | } else if (obj.subtype === 'trustedtype') { |
| 659 | titleElement.appendChild(this._formatParameterAsTrustedType(obj)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 660 | } else { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 661 | UI.UIUtils.createTextChild(titleElement, obj.description || ''); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 662 | } |
| 663 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 664 | if (!obj.hasChildren || obj.customPreview()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 665 | return titleElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 666 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 667 | |
| 668 | const note = titleElement.createChild('span', 'object-state-note info-note'); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 669 | if (this._message.type === SDK.ConsoleModel.FrontendMessageType.QueryObjectResult) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 670 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.thisValueWillNotBeCollectedUntil)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 671 | } else { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 672 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.thisValueWasEvaluatedUponFirst)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 673 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 674 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 675 | const section = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection(obj, titleElement, this._linkifier); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 676 | section.element.classList.add('console-view-object-properties-section'); |
| 677 | section.enableContextMenu(); |
Erik Luo | cc14b81 | 2018-11-03 01:33:09 | [diff] [blame] | 678 | section.setShowSelectionOnKeyboardFocus(true, true); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 679 | this._selectableChildren.push(section); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 680 | section.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 681 | section.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 682 | section.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 683 | return section.element; |
| 684 | } |
| 685 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 686 | _formatParameterAsFunction(func: SDK.RemoteObject.RemoteObject, includePreview?: boolean): HTMLElement { |
| 687 | const result = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 688 | SDK.RemoteObject.RemoteFunction.objectAsFunction(func).targetFunction().then(formatTargetFunction.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 689 | return result; |
| 690 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 691 | function formatTargetFunction(this: ConsoleViewMessage, targetFunction: SDK.RemoteObject.RemoteObject): void { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 692 | const functionElement = document.createElement('span'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 693 | const promise = ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.formatObjectAsFunction( |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 694 | targetFunction, functionElement, true, includePreview); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 695 | result.appendChild(functionElement); |
| 696 | if (targetFunction !== func) { |
| 697 | const note = result.createChild('span', 'object-info-state-note'); |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 698 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.functionWasResolvedFromBound)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 699 | } |
| 700 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, targetFunction), false); |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 701 | promise.then(() => this._formattedParameterAsFunctionForTest()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 705 | _formattedParameterAsFunctionForTest(): void { |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 706 | } |
| 707 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 708 | _contextMenuEventFired(obj: SDK.RemoteObject.RemoteObject, event: Event): void { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 709 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 710 | contextMenu.appendApplicableItems(obj); |
| 711 | contextMenu.show(); |
| 712 | } |
| 713 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 714 | _renderPropertyPreviewOrAccessor( |
| 715 | object: SDK.RemoteObject.RemoteObject|null, property: Protocol.Runtime.PropertyPreview, propertyPath: { |
| 716 | name: (string|symbol), |
| 717 | }[]): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 718 | if (property.type === 'accessor') { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 719 | return this._formatAsAccessorProperty(object, propertyPath.map(property => property.name.toString()), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 720 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 721 | return this._previewFormatter.renderPropertyPreview( |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 722 | property.type, 'subtype' in property ? property.subtype : undefined, null, property.value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 723 | } |
| 724 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 725 | _formatParameterAsNode(remoteObject: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 726 | const result = document.createElement('span'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 727 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 728 | const domModel = remoteObject.runtimeModel().target().model(SDK.DOMModel.DOMModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 729 | if (!domModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 730 | return result; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 731 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 732 | domModel.pushObjectAsNodeToFrontend(remoteObject).then(async (node: SDK.DOMModel.DOMNode|null) => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 733 | if (!node) { |
| 734 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 735 | return; |
| 736 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 737 | const renderResult = await UI.UIUtils.Renderer.render((node as Object)); |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 738 | if (renderResult) { |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 739 | if (renderResult.tree) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 740 | this._selectableChildren.push(renderResult.tree); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 741 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 742 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 743 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
| 744 | } |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 745 | result.appendChild(renderResult.node); |
| 746 | } else { |
| 747 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 748 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 749 | this._formattedParameterAsNodeForTest(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 750 | }); |
| 751 | |
| 752 | return result; |
| 753 | } |
| 754 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 755 | _formattedParameterAsNodeForTest(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 756 | } |
| 757 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 758 | _formatParameterAsString(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
Tim van der Lippe | 8b2737f | 2021-06-21 14:50:47 | [diff] [blame] | 759 | // Properly escape double quotes here, so users don't get surprised |
| 760 | // when they copy strings from the console (https://crbug.com/1178530). |
Benedikt Meurer | 62b49da | 2021-02-18 09:15:55 | [diff] [blame] | 761 | const description = output.description ?? ''; |
Tim van der Lippe | 8b2737f | 2021-06-21 14:50:47 | [diff] [blame] | 762 | const text = JSON.stringify(description); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 763 | const result = (document.createElement('span') as HTMLElement); |
Benedikt Meurer | 62b49da | 2021-02-18 09:15:55 | [diff] [blame] | 764 | result.appendChild(this._linkifyStringAsFragment(text)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 765 | return result; |
| 766 | } |
| 767 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 768 | _formatParameterAsError(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 769 | const result = (document.createElement('span') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 770 | const errorSpan = this._tryFormatAsError(output.description || ''); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 771 | result.appendChild(errorSpan ? errorSpan : this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 772 | return result; |
| 773 | } |
| 774 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 775 | _formatAsArrayEntry(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 776 | return this._previewFormatter.renderPropertyPreview( |
| 777 | output.type, output.subtype, output.className, output.description); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 778 | } |
| 779 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 780 | _formatAsAccessorProperty(object: SDK.RemoteObject.RemoteObject|null, propertyPath: string[], isArrayEntry: boolean): |
| 781 | HTMLElement { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 782 | const rootElement = |
| 783 | ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement.createRemoteObjectAccessorPropertySpan( |
| 784 | object, propertyPath, onInvokeGetterClick.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 785 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 786 | function onInvokeGetterClick(this: ConsoleViewMessage, result: SDK.RemoteObject.CallFunctionResult): void { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 787 | const wasThrown = result.wasThrown; |
| 788 | const object = result.object; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 789 | if (!object) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 790 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 791 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 792 | rootElement.removeChildren(); |
| 793 | if (wasThrown) { |
| 794 | const element = rootElement.createChild('span'); |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 795 | element.textContent = i18nString(UIStrings.exception); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 796 | UI.Tooltip.Tooltip.install(element, (object.description as string)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 797 | } else if (isArrayEntry) { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 798 | rootElement.appendChild(this._formatAsArrayEntry(object)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 799 | } else { |
| 800 | // Make a PropertyPreview from the RemoteObject similar to the backend logic. |
| 801 | const maxLength = 100; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 802 | const type = object.type; |
| 803 | const subtype = object.subtype; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 804 | let description = ''; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 805 | if (type !== 'function' && object.description) { |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 806 | if (type === 'string' || subtype === 'regexp' || subtype === 'trustedtype') { |
Tim van der Lippe | 213266c | 2021-01-18 15:48:31 | [diff] [blame] | 807 | description = Platform.StringUtilities.trimMiddle(object.description, maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 808 | } else { |
Tim van der Lippe | 3cc3af3 | 2021-01-19 14:25:26 | [diff] [blame] | 809 | description = Platform.StringUtilities.trimEndWithMaxLength(object.description, maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 810 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 811 | } |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 812 | rootElement.appendChild( |
| 813 | this._previewFormatter.renderPropertyPreview(type, subtype, object.className, description)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | return rootElement; |
| 818 | } |
| 819 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 820 | _formatWithSubstitutionString( |
| 821 | format: string, parameters: SDK.RemoteObject.RemoteObject[], formattedResult: HTMLElement): { |
| 822 | formattedResult: Element, |
| 823 | unusedSubstitutions: ArrayLike<SDK.RemoteObject.RemoteObject>|null, |
| 824 | } { |
| 825 | function parameterFormatter( |
| 826 | this: ConsoleViewMessage, force: boolean, includePreview: boolean, |
| 827 | obj?: string|SDK.RemoteObject.RemoteObject): string|HTMLElement|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 828 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 829 | return this._formatParameter(obj, force, includePreview); |
| 830 | } |
| 831 | return stringFormatter(obj); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 832 | } |
| 833 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 834 | function stringFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 835 | if (obj === undefined) { |
| 836 | return undefined; |
| 837 | } |
| 838 | if (typeof obj === 'string') { |
| 839 | return obj; |
| 840 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 841 | return obj.description; |
| 842 | } |
| 843 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 844 | function floatFormatter(obj?: string|SDK.RemoteObject.RemoteObject): number|string|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 845 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 846 | if (typeof obj.value !== 'number') { |
| 847 | return 'NaN'; |
| 848 | } |
| 849 | return obj.value; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 850 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 851 | return undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 852 | } |
| 853 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 854 | function integerFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|number|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 855 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 856 | if (obj.type === 'bigint') { |
| 857 | return obj.description; |
| 858 | } |
| 859 | if (typeof obj.value !== 'number') { |
| 860 | return 'NaN'; |
| 861 | } |
| 862 | return Math.floor(obj.value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 863 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 864 | return undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 865 | } |
| 866 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 867 | function bypassFormatter(obj?: string|SDK.RemoteObject.RemoteObject): Node|string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 868 | return (obj instanceof Node) ? obj : ''; |
| 869 | } |
| 870 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 871 | let currentStyle: Map<string, {value: string, priority: string}>|null = null; |
| 872 | function styleFormatter(obj?: string|SDK.RemoteObject.RemoteObject): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 873 | currentStyle = new Map(); |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 874 | const buffer = document.createElement('span'); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 875 | if (obj === undefined) { |
| 876 | return; |
| 877 | } |
| 878 | if (typeof obj === 'string' || !obj.description) { |
| 879 | return; |
| 880 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 881 | buffer.setAttribute('style', obj.description); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 882 | for (const property of buffer.style) { |
Mathias Bynens | 5165a7a | 2020-06-10 05:51:43 | [diff] [blame] | 883 | if (isAllowedProperty(property)) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 884 | const info = { |
| 885 | value: buffer.style.getPropertyValue(property), |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 886 | priority: buffer.style.getPropertyPriority(property), |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 887 | }; |
| 888 | currentStyle.set(property, info); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 889 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 893 | function isAllowedProperty(property: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 894 | // Make sure that allowed properties do not interfere with link visibility. |
| 895 | const prefixes = [ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 896 | 'background', |
| 897 | 'border', |
| 898 | 'color', |
| 899 | 'font', |
| 900 | 'line', |
| 901 | 'margin', |
| 902 | 'padding', |
| 903 | 'text', |
| 904 | '-webkit-background', |
| 905 | '-webkit-border', |
| 906 | '-webkit-font', |
| 907 | '-webkit-margin', |
| 908 | '-webkit-padding', |
| 909 | '-webkit-text', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 910 | ]; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 911 | for (const prefix of prefixes) { |
| 912 | if (property.startsWith(prefix)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 913 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 914 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 915 | } |
| 916 | return false; |
| 917 | } |
| 918 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 919 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration) |
| 920 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 921 | const formatters: Record<string, Platform.StringUtilities.FormatterFunction<any>> = {}; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 922 | // Firebug uses %o for formatting objects. |
| 923 | formatters.o = parameterFormatter.bind(this, false /* force */, true /* includePreview */); |
| 924 | formatters.s = stringFormatter; |
| 925 | formatters.f = floatFormatter; |
| 926 | // Firebug allows both %i and %d for formatting integers. |
| 927 | formatters.i = integerFormatter; |
| 928 | formatters.d = integerFormatter; |
| 929 | |
| 930 | // Firebug uses %c for styling the message. |
| 931 | formatters.c = styleFormatter; |
| 932 | |
| 933 | // Support %O to force object formatting, instead of the type-based %o formatting. |
| 934 | formatters.O = parameterFormatter.bind(this, true /* force */, false /* includePreview */); |
| 935 | |
| 936 | formatters._ = bypassFormatter; |
| 937 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 938 | function append(this: ConsoleViewMessage, a: HTMLElement, b?: string|Node): HTMLElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 939 | if (b instanceof Node) { |
| 940 | a.appendChild(b); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 941 | return a; |
| 942 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 943 | if (typeof b === 'undefined') { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 944 | return a; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 945 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 946 | if (!currentStyle) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 947 | a.appendChild(this._linkifyStringAsFragment(String(b))); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 948 | return a; |
| 949 | } |
| 950 | const lines = String(b).split('\n'); |
| 951 | for (let i = 0; i < lines.length; i++) { |
| 952 | const line = lines[i]; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 953 | const lineFragment = this._linkifyStringAsFragment(line); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 954 | const wrapper = (document.createElement('span') as HTMLElement); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 955 | wrapper.style.setProperty('contain', 'paint'); |
| 956 | wrapper.style.setProperty('display', 'inline-block'); |
| 957 | wrapper.style.setProperty('max-width', '100%'); |
| 958 | wrapper.appendChild(lineFragment); |
| 959 | applyCurrentStyle(wrapper); |
| 960 | for (const child of wrapper.children) { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 961 | if (child.classList.contains('devtools-link') && child instanceof HTMLElement) { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 962 | this._applyForcedVisibleStyle(child); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 963 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 964 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 965 | a.appendChild(wrapper); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 966 | if (i < lines.length - 1) { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 967 | a.appendChild(document.createElement('br')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 968 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 969 | } |
| 970 | return a; |
| 971 | } |
| 972 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 973 | function applyCurrentStyle(element: HTMLElement): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 974 | if (!currentStyle) { |
| 975 | return; |
| 976 | } |
| 977 | for (const [property, {value, priority}] of currentStyle.entries()) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 978 | element.style.setProperty((property as string), value, priority); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 979 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 980 | } |
| 981 | |
Tim van der Lippe | 93b57c3 | 2020-02-20 17:38:44 | [diff] [blame] | 982 | // Platform.StringUtilities.format does treat formattedResult like a Builder, result is an object. |
| 983 | return Platform.StringUtilities.format(format, parameters, formatters, formattedResult, append.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 984 | } |
| 985 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 986 | _applyForcedVisibleStyle(element: HTMLElement): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 987 | element.style.setProperty('-webkit-text-stroke', '0', 'important'); |
| 988 | element.style.setProperty('text-decoration', 'underline', 'important'); |
| 989 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 990 | const themedColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 991 | 'rgb(33%, 33%, 33%)', ThemeSupport.ThemeSupport.ColorUsage.Foreground); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 992 | element.style.setProperty('color', themedColor, 'important'); |
| 993 | |
| 994 | let backgroundColor = 'hsl(0, 0%, 100%)'; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 995 | if (this._message.level === Protocol.Log.LogEntryLevel.Error) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 996 | backgroundColor = 'hsl(0, 100%, 97%)'; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 997 | } else if (this._message.level === Protocol.Log.LogEntryLevel.Warning || this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 998 | backgroundColor = 'hsl(50, 100%, 95%)'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 999 | } |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1000 | const themedBackgroundColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 1001 | backgroundColor, ThemeSupport.ThemeSupport.ColorUsage.Background); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1002 | element.style.setProperty('background-color', themedBackgroundColor, 'important'); |
| 1003 | } |
| 1004 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1005 | matchesFilterRegex(regexObject: RegExp): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1006 | regexObject.lastIndex = 0; |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 1007 | const contentElement = this.contentElement(); |
| 1008 | const anchorText = this._anchorElement ? this._anchorElement.deepTextContent() : ''; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1009 | return (Boolean(anchorText) && regexObject.test(anchorText.trim())) || |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 1010 | regexObject.test(contentElement.deepTextContent().slice(anchorText.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1011 | } |
| 1012 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1013 | matchesFilterText(filter: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1014 | const text = this.contentElement().deepTextContent(); |
| 1015 | return text.toLowerCase().includes(filter.toLowerCase()); |
| 1016 | } |
| 1017 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1018 | updateTimestamp(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1019 | if (!this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1020 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1021 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1022 | |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 1023 | if (Common.Settings.Settings.instance().moduleSetting('consoleTimestampsEnabled').get()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1024 | if (!this._timestampElement) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1025 | this._timestampElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1026 | this._timestampElement.classList.add('console-timestamp'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1027 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1028 | this._timestampElement.textContent = UI.UIUtils.formatTimestamp(this._message.timestamp, false) + ' '; |
Tim van der Lippe | 70842f3 | 2020-11-23 16:56:57 | [diff] [blame] | 1029 | UI.Tooltip.Tooltip.install(this._timestampElement, UI.UIUtils.formatTimestamp(this._message.timestamp, true)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1030 | this._contentElement.insertBefore(this._timestampElement, this._contentElement.firstChild); |
| 1031 | } else if (this._timestampElement) { |
| 1032 | this._timestampElement.remove(); |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 1033 | this._timestampElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1034 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1035 | } |
| 1036 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1037 | nestingLevel(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1038 | return this._nestingLevel; |
| 1039 | } |
| 1040 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1041 | setInSimilarGroup(inSimilarGroup: boolean, isLast?: boolean): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1042 | this._inSimilarGroup = inSimilarGroup; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1043 | this._lastInSimilarGroup = inSimilarGroup && Boolean(isLast); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1044 | if (this._similarGroupMarker && !inSimilarGroup) { |
| 1045 | this._similarGroupMarker.remove(); |
| 1046 | this._similarGroupMarker = null; |
| 1047 | } else if (this._element && !this._similarGroupMarker && inSimilarGroup) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1048 | this._similarGroupMarker = (document.createElement('div') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1049 | this._similarGroupMarker.classList.add('nesting-level-marker'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1050 | this._element.insertBefore(this._similarGroupMarker, this._element.firstChild); |
| 1051 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1052 | } |
| 1053 | } |
| 1054 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1055 | isLastInSimilarGroup(): boolean { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1056 | return Boolean(this._inSimilarGroup) && Boolean(this._lastInSimilarGroup); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1057 | } |
| 1058 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1059 | resetCloseGroupDecorationCount(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1060 | if (!this._closeGroupDecorationCount) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1061 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1062 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1063 | this._closeGroupDecorationCount = 0; |
| 1064 | this._updateCloseGroupDecorations(); |
| 1065 | } |
| 1066 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1067 | incrementCloseGroupDecorationCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1068 | ++this._closeGroupDecorationCount; |
| 1069 | this._updateCloseGroupDecorations(); |
| 1070 | } |
| 1071 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1072 | _updateCloseGroupDecorations(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1073 | if (!this._nestingLevelMarkers) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1074 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1075 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1076 | for (let i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
| 1077 | const marker = this._nestingLevelMarkers[i]; |
| 1078 | marker.classList.toggle('group-closed', n - i <= this._closeGroupDecorationCount); |
| 1079 | } |
| 1080 | } |
| 1081 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1082 | _focusedChildIndex(): number { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1083 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1084 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1085 | } |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1086 | return this._selectableChildren.findIndex(child => child.element.hasFocus()); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1087 | } |
| 1088 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1089 | _onKeyDown(event: KeyboardEvent): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1090 | if (UI.UIUtils.isEditing() || !this._element || !this._element.hasFocus() || this._element.hasSelection()) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1091 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1092 | } |
| 1093 | if (this.maybeHandleOnKeyDown(event)) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1094 | event.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1095 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1096 | } |
| 1097 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1098 | maybeHandleOnKeyDown(event: KeyboardEvent): boolean { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1099 | // Handle trace expansion. |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1100 | const focusedChildIndex = this._focusedChildIndex(); |
| 1101 | const isWrapperFocused = focusedChildIndex === -1; |
| 1102 | if (this._expandTrace && isWrapperFocused) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1103 | if ((event.key === 'ArrowLeft' && this._traceExpanded) || (event.key === 'ArrowRight' && !this._traceExpanded)) { |
| 1104 | this._expandTrace(!this._traceExpanded); |
| 1105 | return true; |
| 1106 | } |
| 1107 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1108 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1109 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1110 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1111 | |
| 1112 | if (event.key === 'ArrowLeft') { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1113 | this._element && this._element.focus(); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1114 | return true; |
| 1115 | } |
| 1116 | if (event.key === 'ArrowRight') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1117 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1118 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1119 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1120 | } |
| 1121 | if (event.key === 'ArrowUp') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1122 | const firstVisibleChild = this._nearestVisibleChild(0); |
| 1123 | if (this._selectableChildren[focusedChildIndex] === firstVisibleChild && firstVisibleChild) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1124 | this._element && this._element.focus(); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1125 | return true; |
Mathias Bynens | f06e8c0 | 2020-02-28 13:58:28 | [diff] [blame] | 1126 | } |
| 1127 | if (this._selectNearestVisibleChild(focusedChildIndex - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1128 | return true; |
| 1129 | } |
| 1130 | } |
| 1131 | if (event.key === 'ArrowDown') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1132 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1133 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1134 | } |
| 1135 | if (!isWrapperFocused && this._selectNearestVisibleChild(focusedChildIndex + 1)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1136 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1137 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1138 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1139 | return false; |
| 1140 | } |
| 1141 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1142 | _selectNearestVisibleChild(fromIndex: number, backwards?: boolean): boolean { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1143 | const nearestChild = this._nearestVisibleChild(fromIndex, backwards); |
| 1144 | if (nearestChild) { |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1145 | nearestChild.forceSelect(); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1146 | return true; |
| 1147 | } |
| 1148 | return false; |
| 1149 | } |
| 1150 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1151 | _nearestVisibleChild(fromIndex: number, backwards?: boolean): { |
| 1152 | element: Element, |
| 1153 | forceSelect: () => void, |
| 1154 | }|null { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1155 | const childCount = this._selectableChildren.length; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1156 | if (fromIndex < 0 || fromIndex >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1157 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1158 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1159 | const direction = backwards ? -1 : 1; |
| 1160 | let index = fromIndex; |
| 1161 | |
| 1162 | while (!this._selectableChildren[index].element.offsetParent) { |
| 1163 | index += direction; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1164 | if (index < 0 || index >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1165 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1166 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1167 | } |
| 1168 | return this._selectableChildren[index]; |
| 1169 | } |
| 1170 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1171 | focusLastChildOrSelf(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1172 | if (this._element && !this._selectNearestVisibleChild(this._selectableChildren.length - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1173 | this._element.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1174 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1175 | } |
| 1176 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1177 | setContentElement(element: HTMLElement): void { |
Sigurd Schneider | b2953b2 | 2020-10-09 09:30:15 | [diff] [blame] | 1178 | console.assert(!this._contentElement, 'Cannot set content element twice'); |
| 1179 | this._contentElement = element; |
| 1180 | } |
| 1181 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1182 | getContentElement(): HTMLElement|null { |
Sigurd Schneider | b2953b2 | 2020-10-09 09:30:15 | [diff] [blame] | 1183 | return this._contentElement; |
| 1184 | } |
| 1185 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1186 | contentElement(): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1187 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1188 | return this._contentElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1189 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1190 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1191 | const contentElement = (document.createElement('div') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1192 | contentElement.classList.add('console-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1193 | if (this._messageLevelIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1194 | contentElement.appendChild(this._messageLevelIcon); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1195 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1196 | this._contentElement = contentElement; |
| 1197 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1198 | const runtimeModel = this._message.runtimeModel(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1199 | let formattedMessage; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1200 | const shouldIncludeTrace = Boolean(this._message.stackTrace) && |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1201 | (this._message.source === Protocol.Log.LogEntrySource.Network || |
| 1202 | this._message.source === Protocol.Log.LogEntrySource.Violation || |
| 1203 | this._message.level === Protocol.Log.LogEntryLevel.Error || |
| 1204 | this._message.level === Protocol.Log.LogEntryLevel.Warning || |
| 1205 | this._message.type === Protocol.Runtime.ConsoleAPICalledEventType.Trace); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1206 | if (runtimeModel && shouldIncludeTrace) { |
| 1207 | formattedMessage = this._buildMessageWithStackTrace(runtimeModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1208 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1209 | formattedMessage = this._buildMessage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1210 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1211 | contentElement.appendChild(formattedMessage); |
| 1212 | |
| 1213 | this.updateTimestamp(); |
| 1214 | return this._contentElement; |
| 1215 | } |
| 1216 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1217 | toMessageElement(): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1218 | if (this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1219 | return this._element; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1220 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1221 | this._element = (document.createElement('div') as HTMLElement); |
Pavel Feldman | db31091 | 2019-01-30 00:31:20 | [diff] [blame] | 1222 | this._element.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1223 | this._element.addEventListener('keydown', (this._onKeyDown.bind(this) as EventListener)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1224 | this.updateMessageElement(); |
| 1225 | return this._element; |
| 1226 | } |
| 1227 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1228 | updateMessageElement(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1229 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1230 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1231 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1232 | |
| 1233 | this._element.className = 'console-message-wrapper'; |
| 1234 | this._element.removeChildren(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1235 | if (this._message.isGroupStartMessage()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1236 | this._element.classList.add('console-group-title'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1237 | } |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1238 | if (this._message.source === SDK.ConsoleModel.FrontendMessageSource.ConsoleAPI) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1239 | this._element.classList.add('console-from-api'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1240 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1241 | if (this._inSimilarGroup) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1242 | this._similarGroupMarker = (this._element.createChild('div', 'nesting-level-marker') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1243 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1244 | } |
| 1245 | |
| 1246 | this._nestingLevelMarkers = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1247 | for (let i = 0; i < this._nestingLevel; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-level-marker')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1249 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1250 | this._updateCloseGroupDecorations(); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1251 | elementToMessage.set(this._element, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1252 | |
| 1253 | switch (this._message.level) { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1254 | case Protocol.Log.LogEntryLevel.Verbose: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1255 | this._element.classList.add('console-verbose-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1256 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1257 | case Protocol.Log.LogEntryLevel.Info: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1258 | this._element.classList.add('console-info-level'); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1259 | if (this._message.type === SDK.ConsoleModel.FrontendMessageType.System) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1260 | this._element.classList.add('console-system-type'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1261 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1262 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1263 | case Protocol.Log.LogEntryLevel.Warning: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1264 | this._element.classList.add('console-warning-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1265 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1266 | case Protocol.Log.LogEntryLevel.Error: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1267 | this._element.classList.add('console-error-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1268 | break; |
| 1269 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1270 | this._updateMessageLevelIcon(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1271 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1272 | this._element.classList.add('console-warning-level'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1273 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1274 | |
| 1275 | this._element.appendChild(this.contentElement()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1276 | if (this._repeatCount > 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1277 | this._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1278 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1279 | } |
| 1280 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1281 | _shouldRenderAsWarning(): boolean { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1282 | return (this._message.level === Protocol.Log.LogEntryLevel.Verbose || |
| 1283 | this._message.level === Protocol.Log.LogEntryLevel.Info) && |
| 1284 | (this._message.source === Protocol.Log.LogEntrySource.Violation || |
| 1285 | this._message.source === Protocol.Log.LogEntrySource.Deprecation || |
| 1286 | this._message.source === Protocol.Log.LogEntrySource.Intervention || |
| 1287 | this._message.source === Protocol.Log.LogEntrySource.Recommendation); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1288 | } |
| 1289 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1290 | _updateMessageLevelIcon(): void { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1291 | let iconType = ''; |
| 1292 | let accessibleName = ''; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1293 | if (this._message.level === Protocol.Log.LogEntryLevel.Warning) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1294 | iconType = 'smallicon-warning'; |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1295 | accessibleName = i18nString(UIStrings.warning); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1296 | } else if (this._message.level === Protocol.Log.LogEntryLevel.Error) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1297 | iconType = 'smallicon-error'; |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1298 | accessibleName = i18nString(UIStrings.error); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1299 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1300 | if (!this._messageLevelIcon) { |
| 1301 | if (!iconType) { |
| 1302 | return; |
| 1303 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1304 | this._messageLevelIcon = UI.Icon.Icon.create('', 'message-level-icon'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1305 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1306 | this._contentElement.insertBefore(this._messageLevelIcon, this._contentElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1307 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1308 | } |
| 1309 | this._messageLevelIcon.setIconType(iconType); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1310 | UI.ARIAUtils.setAccessibleName(this._messageLevelIcon, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1311 | } |
| 1312 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1313 | repeatCount(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1314 | return this._repeatCount || 1; |
| 1315 | } |
| 1316 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1317 | resetIncrementRepeatCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1318 | this._repeatCount = 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1319 | if (!this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1320 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1321 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1322 | |
| 1323 | this._repeatCountElement.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1324 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1325 | this._contentElement.classList.remove('repeated-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1326 | } |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 1327 | this._repeatCountElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1328 | } |
| 1329 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1330 | incrementRepeatCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1331 | this._repeatCount++; |
| 1332 | this._showRepeatCountElement(); |
| 1333 | } |
| 1334 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1335 | setRepeatCount(repeatCount: number): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1336 | this._repeatCount = repeatCount; |
| 1337 | this._showRepeatCountElement(); |
| 1338 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1339 | _showRepeatCountElement(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1340 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1341 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1342 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1343 | |
| 1344 | if (!this._repeatCountElement) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1345 | this._repeatCountElement = |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1346 | (document.createElement('span', {is: 'dt-small-bubble'}) as UI.UIUtils.DevToolsSmallBubble); |
Tim van der Lippe | ee954d4 | 2020-05-04 10:35:57 | [diff] [blame] | 1347 | this._repeatCountElement.classList.add('console-message-repeat-count'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1348 | switch (this._message.level) { |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1349 | case Protocol.Log.LogEntryLevel.Warning: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1350 | this._repeatCountElement.type = 'warning'; |
| 1351 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1352 | case Protocol.Log.LogEntryLevel.Error: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1353 | this._repeatCountElement.type = 'error'; |
| 1354 | break; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1355 | case Protocol.Log.LogEntryLevel.Verbose: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1356 | this._repeatCountElement.type = 'verbose'; |
| 1357 | break; |
| 1358 | default: |
| 1359 | this._repeatCountElement.type = 'info'; |
| 1360 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1361 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1362 | this._repeatCountElement.type = 'warning'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1363 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1364 | |
| 1365 | this._element.insertBefore(this._repeatCountElement, this._contentElement); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1366 | this.contentElement().classList.add('repeated-message'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1367 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1368 | this._repeatCountElement.textContent = `${this._repeatCount}`; |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1369 | |
| 1370 | let accessibleName; |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1371 | if (this._message.level === Protocol.Log.LogEntryLevel.Warning) { |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1372 | accessibleName = i18nString(UIStrings.warningS, {n: this._repeatCount}); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1373 | } else if (this._message.level === Protocol.Log.LogEntryLevel.Error) { |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1374 | accessibleName = i18nString(UIStrings.errorS, {n: this._repeatCount}); |
| 1375 | } else { |
| 1376 | accessibleName = i18nString(UIStrings.repeatS, {n: this._repeatCount}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1377 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1378 | UI.ARIAUtils.setAccessibleName(this._repeatCountElement, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1379 | } |
| 1380 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1381 | get text(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1382 | return this._message.messageText; |
| 1383 | } |
| 1384 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1385 | toExportString(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1386 | const lines = []; |
| 1387 | const nodes = this.contentElement().childTextNodes(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1388 | const messageContent = nodes.map(Components.Linkifier.Linkifier.untruncatedNodeText).join(''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1389 | for (let i = 0; i < this.repeatCount(); ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1390 | lines.push(messageContent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1391 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1392 | return lines.join('\n'); |
| 1393 | } |
| 1394 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1395 | setSearchRegex(regex: RegExp|null): void { |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1396 | if (this._searchHighlightNodeChanges && this._searchHighlightNodeChanges.length) { |
| 1397 | UI.UIUtils.revertDomChanges(this._searchHighlightNodeChanges); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1398 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1399 | this._searchRegex = regex; |
| 1400 | this._searchHighlightNodes = []; |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1401 | this._searchHighlightNodeChanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1402 | if (!this._searchRegex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1403 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1404 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1405 | |
| 1406 | const text = this.contentElement().deepTextContent(); |
| 1407 | let match; |
| 1408 | this._searchRegex.lastIndex = 0; |
| 1409 | const sourceRanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1410 | while ((match = this._searchRegex.exec(text)) && match[0]) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1411 | sourceRanges.push(new TextUtils.TextRange.SourceRange(match.index, match[0].length)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1412 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1413 | |
| 1414 | if (sourceRanges.length) { |
| 1415 | this._searchHighlightNodes = |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1416 | UI.UIUtils.highlightSearchResults(this.contentElement(), sourceRanges, this._searchHighlightNodeChanges); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1420 | searchRegex(): RegExp|null { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1421 | return this._searchRegex; |
| 1422 | } |
| 1423 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1424 | searchCount(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1425 | return this._searchHighlightNodes.length; |
| 1426 | } |
| 1427 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1428 | searchHighlightNode(index: number): Element { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1429 | return this._searchHighlightNodes[index]; |
| 1430 | } |
| 1431 | |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1432 | async _getInlineFrames( |
| 1433 | debuggerModel: SDK.DebuggerModel.DebuggerModel, url: string, lineNumber: number|undefined, |
| 1434 | columnNumber: number|undefined): Promise<{frames: Bindings.DebuggerLanguagePlugins.FunctionInfo[]}> { |
| 1435 | const debuggerWorkspaceBinding = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(); |
| 1436 | if (debuggerWorkspaceBinding.pluginManager) { |
| 1437 | const projects = Workspace.Workspace.WorkspaceImpl.instance().projects(); |
| 1438 | const uiSourceCodes = projects.map(project => project.uiSourceCodeForURL(url)).flat().filter(f => Boolean(f)) as |
| 1439 | Workspace.UISourceCode.UISourceCode[]; |
| 1440 | const scripts = |
| 1441 | uiSourceCodes.map(uiSourceCode => debuggerWorkspaceBinding.scriptsForUISourceCode(uiSourceCode)).flat(); |
| 1442 | if (scripts.length) { |
| 1443 | const location = |
| 1444 | new SDK.DebuggerModel.Location(debuggerModel, scripts[0].scriptId, lineNumber || 0, columnNumber); |
| 1445 | return debuggerWorkspaceBinding.pluginManager.getFunctionInfo(scripts[0], location); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | return {frames: []}; |
| 1450 | } |
| 1451 | |
| 1452 | // Expand inline stack frames in the formatted error in the stackTrace element, inserting new elements before the |
| 1453 | // insertBefore anchor. |
| 1454 | async _expandInlineStackFrames( |
| 1455 | debuggerModel: SDK.DebuggerModel.DebuggerModel, prefix: string, suffix: string, url: string, |
| 1456 | lineNumber: number|undefined, columnNumber: number|undefined, stackTrace: HTMLElement, |
| 1457 | insertBefore: HTMLElement): Promise<boolean> { |
| 1458 | const {frames} = await this._getInlineFrames(debuggerModel, url, lineNumber, columnNumber); |
| 1459 | if (!frames.length) { |
| 1460 | return false; |
| 1461 | } |
| 1462 | |
| 1463 | for (let f = 0; f < frames.length; ++f) { |
| 1464 | const {name} = frames[f]; |
| 1465 | const formattedLine = document.createElement('span'); |
| 1466 | formattedLine.appendChild(this._linkifyStringAsFragment(`${prefix} ${name} (`)); |
| 1467 | const scriptLocationLink = this._linkifier.linkifyScriptLocation( |
| 1468 | debuggerModel.target(), null, url, lineNumber, |
| 1469 | {columnNumber, className: undefined, tabStop: undefined, inlineFrameIndex: f}); |
| 1470 | scriptLocationLink.tabIndex = -1; |
| 1471 | this._selectableChildren.push({element: scriptLocationLink, forceSelect: (): void => scriptLocationLink.focus()}); |
| 1472 | formattedLine.appendChild(scriptLocationLink); |
| 1473 | formattedLine.appendChild(this._linkifyStringAsFragment(suffix)); |
| 1474 | stackTrace.insertBefore(formattedLine, insertBefore); |
| 1475 | } |
| 1476 | return true; |
| 1477 | } |
| 1478 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1479 | _tryFormatAsError(string: string): HTMLElement|null { |
| 1480 | function startsWith(prefix: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1481 | return string.startsWith(prefix); |
| 1482 | } |
| 1483 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1484 | const runtimeModel = this._message.runtimeModel(); |
Sigurd Schneider | 8d0fe54 | 2021-03-17 12:28:29 | [diff] [blame] | 1485 | // TODO: Consider removing these in favor of a simpler regex. |
Mathias Bynens | fdcb301 | 2021-03-17 14:07:21 | [diff] [blame] | 1486 | const errorPrefixes = [ |
| 1487 | 'AggregateError', |
| 1488 | 'Error', |
| 1489 | 'EvalError', |
| 1490 | 'RangeError', |
| 1491 | 'ReferenceError', |
| 1492 | 'SyntaxError', |
| 1493 | 'TypeError', |
| 1494 | 'URIError', |
| 1495 | ]; |
Sigurd Schneider | 8d0fe54 | 2021-03-17 12:28:29 | [diff] [blame] | 1496 | if (!runtimeModel || !errorPrefixes.some(startsWith) && !/^[\w.]+Error\b/.test(string)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1497 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1498 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1499 | const debuggerModel = runtimeModel.debuggerModel(); |
| 1500 | const baseURL = runtimeModel.target().inspectedURL(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1501 | |
| 1502 | const lines = string.split('\n'); |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1503 | const linkInfos = []; |
| 1504 | for (const line of lines) { |
| 1505 | const isCallFrameLine = /^\s*at\s/.test(line); |
| 1506 | if (!isCallFrameLine && linkInfos.length && linkInfos[linkInfos.length - 1].link) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1507 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1508 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1509 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1510 | if (!isCallFrameLine) { |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1511 | linkInfos.push({line}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1512 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1513 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1514 | |
| 1515 | let openBracketIndex = -1; |
| 1516 | let closeBracketIndex = -1; |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1517 | const inBracketsWithLineAndColumn = /\([^\)\(]+:\d+:\d+\)/g; |
| 1518 | const inBrackets = /\([^\)\(]+\)/g; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1519 | let lastMatch: RegExpExecArray|null = null; |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1520 | let currentMatch; |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1521 | while ((currentMatch = inBracketsWithLineAndColumn.exec(line))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1522 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1523 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1524 | if (!lastMatch) { |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1525 | while ((currentMatch = inBrackets.exec(line))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1526 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1527 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1528 | } |
| 1529 | if (lastMatch) { |
| 1530 | openBracketIndex = lastMatch.index; |
| 1531 | closeBracketIndex = lastMatch.index + lastMatch[0].length - 1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1532 | } |
| 1533 | const hasOpenBracket = openBracketIndex !== -1; |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1534 | let left = hasOpenBracket ? openBracketIndex + 1 : line.indexOf('at') + 3; |
| 1535 | if (!hasOpenBracket && line.indexOf('async ') === left) { |
Benedikt Meurer | aef3b59 | 2021-03-17 16:34:40 | [diff] [blame] | 1536 | left += 6; |
| 1537 | } |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1538 | const right = hasOpenBracket ? closeBracketIndex : line.length; |
| 1539 | const linkCandidate = line.substring(left, right); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1540 | const splitResult = Common.ParsedURL.ParsedURL.splitLineAndColumn(linkCandidate); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1541 | if (!splitResult) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1542 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1543 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1544 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1545 | if (splitResult.url === '<anonymous>') { |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1546 | linkInfos.push({line}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1547 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1548 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1549 | let url = parseOrScriptMatch(splitResult.url); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1550 | if (!url && Common.ParsedURL.ParsedURL.isRelativeURL(splitResult.url)) { |
| 1551 | url = parseOrScriptMatch(Common.ParsedURL.ParsedURL.completeURL(baseURL, splitResult.url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1552 | } |
| 1553 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1554 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1555 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1556 | |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1557 | linkInfos.push({ |
| 1558 | line, |
| 1559 | link: { |
| 1560 | url, |
| 1561 | enclosedInBraces: hasOpenBracket, |
| 1562 | positionLeft: left, |
| 1563 | positionRight: right, |
| 1564 | lineNumber: splitResult.lineNumber, |
| 1565 | columnNumber: splitResult.columnNumber, |
| 1566 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1567 | }); |
| 1568 | } |
| 1569 | |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1570 | if (!linkInfos.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1571 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1572 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1573 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1574 | const formattedResult = document.createElement('span'); |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1575 | for (let i = 0; i < linkInfos.length; ++i) { |
| 1576 | const newline = i < linkInfos.length - 1 ? '\n' : ''; |
| 1577 | const {line, link} = linkInfos[i]; |
| 1578 | if (!link) { |
| 1579 | formattedResult.appendChild(this._linkifyStringAsFragment(`${line}${newline}`)); |
| 1580 | continue; |
| 1581 | } |
| 1582 | const formattedLine = document.createElement('span'); |
| 1583 | const prefix = line.substring(0, link.positionLeft); |
| 1584 | const suffix = `${line.substring(link.positionRight)}${newline}`; |
| 1585 | |
| 1586 | formattedLine.appendChild(this._linkifyStringAsFragment(prefix)); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1587 | const scriptLocationLink = this._linkifier.linkifyScriptLocation( |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1588 | debuggerModel.target(), null, link.url, link.lineNumber, |
| 1589 | {columnNumber: link.columnNumber, className: undefined, tabStop: undefined, inlineFrameIndex: 0}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1590 | scriptLocationLink.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1591 | this._selectableChildren.push({element: scriptLocationLink, forceSelect: (): void => scriptLocationLink.focus()}); |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1592 | formattedLine.appendChild(scriptLocationLink); |
| 1593 | formattedLine.appendChild(this._linkifyStringAsFragment(suffix)); |
| 1594 | formattedResult.appendChild(formattedLine); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1595 | |
Philip Pfaffe | 068b01d | 2021-03-22 09:46:26 | [diff] [blame] | 1596 | if (!link.enclosedInBraces) { |
| 1597 | continue; |
| 1598 | } |
| 1599 | |
| 1600 | const prefixWithoutFunction = prefix.substring(0, prefix.lastIndexOf(' ', prefix.length - 3)); |
| 1601 | |
| 1602 | // If we were able to parse the function name from the stack trace line, try to replace it with an expansion of |
| 1603 | // any inline frames. |
| 1604 | const selectableChildIndex = this._selectableChildren.length - 1; |
| 1605 | this._expandInlineStackFrames( |
| 1606 | debuggerModel, prefixWithoutFunction, suffix, link.url, link.lineNumber, link.columnNumber, |
| 1607 | formattedResult, formattedLine) |
| 1608 | .then(modified => { |
| 1609 | if (modified) { |
| 1610 | formattedResult.removeChild(formattedLine); |
| 1611 | this._selectableChildren.splice(selectableChildIndex, 1); |
| 1612 | } |
| 1613 | }); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1614 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1615 | |
| 1616 | return formattedResult; |
| 1617 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1618 | function parseOrScriptMatch(url: string|null): string|null { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1619 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1620 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1621 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1622 | const parsedURL = Common.ParsedURL.ParsedURL.fromString(url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1623 | if (parsedURL) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1624 | return parsedURL.url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1625 | } |
| 1626 | if (debuggerModel.scriptsForSourceURL(url).length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1627 | return url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1628 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1629 | return null; |
| 1630 | } |
| 1631 | } |
| 1632 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1633 | _linkifyWithCustomLinkifier( |
| 1634 | string: string, linkifier: (arg0: string, arg1: string, arg2?: number, arg3?: number) => Node): DocumentFragment { |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1635 | if (string.length > getMaxTokenizableStringLength()) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1636 | const propertyValue = new ObjectUI.ObjectPropertiesSection.ExpandableTextPropertyValue( |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1637 | document.createElement('span'), string, getLongStringVisibleLength()); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1638 | const fragment = document.createDocumentFragment(); |
Connor Moody | 1a5c0d3 | 2019-12-19 07:23:36 | [diff] [blame] | 1639 | fragment.appendChild(propertyValue.element); |
| 1640 | return fragment; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1641 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1642 | const container = document.createDocumentFragment(); |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 1643 | const tokens = ConsoleViewMessage._tokenizeMessageText(string); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1644 | for (const token of tokens) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1645 | if (!token.text) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1646 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1647 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1648 | switch (token.type) { |
| 1649 | case 'url': { |
| 1650 | const realURL = (token.text.startsWith('www.') ? 'http://' + token.text : token.text); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1651 | const splitResult = Common.ParsedURL.ParsedURL.splitLineAndColumn(realURL); |
Kim-Anh Tran | 9e49a45 | 2020-02-17 09:46:10 | [diff] [blame] | 1652 | const sourceURL = Common.ParsedURL.ParsedURL.removeWasmFunctionInfoFromURL(splitResult.url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1653 | let linkNode; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1654 | if (splitResult) { |
Kim-Anh Tran | 9e49a45 | 2020-02-17 09:46:10 | [diff] [blame] | 1655 | linkNode = linkifier(token.text, sourceURL, splitResult.lineNumber, splitResult.columnNumber); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1656 | } else { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1657 | linkNode = linkifier(token.text, ''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1658 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1659 | container.appendChild(linkNode); |
| 1660 | break; |
| 1661 | } |
| 1662 | default: |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1663 | container.appendChild(document.createTextNode(token.text)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1664 | break; |
| 1665 | } |
| 1666 | } |
| 1667 | return container; |
| 1668 | } |
| 1669 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1670 | _linkifyStringAsFragment(string: string): DocumentFragment { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1671 | return this._linkifyWithCustomLinkifier(string, (text, url, lineNumber, columnNumber) => { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1672 | const options = {text, lineNumber, columnNumber}; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1673 | const linkElement = |
| 1674 | Components.Linkifier.Linkifier.linkifyURL(url, (options as Components.Linkifier.LinkifyURLOptions)); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1675 | linkElement.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1676 | this._selectableChildren.push({element: linkElement, forceSelect: (): void => linkElement.focus()}); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1677 | return linkElement; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1678 | }); |
| 1679 | } |
| 1680 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1681 | static _tokenizeMessageText(string: string): { |
| 1682 | type?: string, text: string, |
| 1683 | }[] { |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1684 | const {tokenizerRegexes, tokenizerTypes} = getOrCreateTokenizers(); |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1685 | if (string.length > getMaxTokenizableStringLength()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1686 | return [{text: string, type: undefined}]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1687 | } |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1688 | const results = TextUtils.TextUtils.Utils.splitStringByRegexes(string, tokenizerRegexes); |
| 1689 | return results.map(result => ({text: result.value, type: tokenizerTypes[result.regexIndex]})); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1690 | } |
| 1691 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1692 | groupKey(): string { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1693 | if (!this._groupKey) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1694 | this._groupKey = this._message.groupCategoryKey() + ':' + this.groupTitle(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1695 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1696 | return this._groupKey; |
| 1697 | } |
| 1698 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1699 | groupTitle(): string { |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 1700 | const tokens = ConsoleViewMessage._tokenizeMessageText(this._message.messageText); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1701 | const result = tokens.reduce((acc, token) => { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1702 | let text: Common.UIString.LocalizedString|string = token.text; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1703 | if (token.type === 'url') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1704 | text = i18nString(UIStrings.url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1705 | } else if (token.type === 'time') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1706 | text = i18nString(UIStrings.tookNms); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1707 | } else if (token.type === 'event') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1708 | text = i18nString(UIStrings.someEvent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1709 | } else if (token.type === 'milestone') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1710 | text = i18nString(UIStrings.Mxx); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1711 | } else if (token.type === 'autofill') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1712 | text = i18nString(UIStrings.attribute); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1713 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1714 | return acc + text; |
| 1715 | }, ''); |
| 1716 | return result.replace(/[%]o/g, ''); |
| 1717 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1718 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1719 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1720 | let tokenizerRegexes: RegExp[]|null = null; |
| 1721 | let tokenizerTypes: string[]|null = null; |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1722 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1723 | function getOrCreateTokenizers(): { |
| 1724 | tokenizerRegexes: Array<RegExp>, |
| 1725 | tokenizerTypes: Array<string>, |
| 1726 | } { |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1727 | if (!tokenizerRegexes || !tokenizerTypes) { |
| 1728 | const controlCodes = '\\u0000-\\u0020\\u007f-\\u009f'; |
| 1729 | const linkStringRegex = new RegExp( |
| 1730 | '(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s' + controlCodes + '"]{2,}[^\\s' + controlCodes + |
| 1731 | '"\')}\\],:;.!?]', |
| 1732 | 'u'); |
| 1733 | const pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; |
| 1734 | const timeRegex = /took [\d]+ms/; |
| 1735 | const eventRegex = /'\w+' event/; |
| 1736 | const milestoneRegex = /\sM[6-7]\d/; |
| 1737 | const autofillRegex = /\(suggested: \"[\w-]+\"\)/; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1738 | const handlers = new Map<RegExp, string>(); |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1739 | handlers.set(linkStringRegex, 'url'); |
| 1740 | handlers.set(pathLineRegex, 'url'); |
| 1741 | handlers.set(timeRegex, 'time'); |
| 1742 | handlers.set(eventRegex, 'event'); |
| 1743 | handlers.set(milestoneRegex, 'milestone'); |
| 1744 | handlers.set(autofillRegex, 'autofill'); |
| 1745 | tokenizerRegexes = Array.from(handlers.keys()); |
| 1746 | tokenizerTypes = Array.from(handlers.values()); |
| 1747 | return {tokenizerRegexes, tokenizerTypes}; |
| 1748 | } |
| 1749 | return {tokenizerRegexes, tokenizerTypes}; |
| 1750 | } |
| 1751 | |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1752 | export class ConsoleGroupViewMessage extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1753 | _collapsed: boolean; |
| 1754 | _expandGroupIcon: UI.Icon.Icon|null; |
| 1755 | _onToggle: () => void; |
| 1756 | |
| 1757 | constructor( |
| 1758 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1759 | onToggle: () => void, onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1760 | console.assert(consoleMessage.isGroupStartMessage()); |
Tim van der Lippe | b45d9a0 | 2019-11-05 17:24:41 | [diff] [blame] | 1761 | super(consoleMessage, linkifier, nestingLevel, onResize); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1762 | this._collapsed = consoleMessage.type === Protocol.Runtime.ConsoleAPICalledEventType.StartGroupCollapsed; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1763 | this._expandGroupIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1764 | this._onToggle = onToggle; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1765 | } |
| 1766 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1767 | _setCollapsed(collapsed: boolean): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1768 | this._collapsed = collapsed; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1769 | if (this._expandGroupIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1770 | this._expandGroupIcon.setIconType(this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1771 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1772 | this._onToggle.call(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1773 | } |
| 1774 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1775 | collapsed(): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1776 | return this._collapsed; |
| 1777 | } |
| 1778 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1779 | maybeHandleOnKeyDown(event: KeyboardEvent): boolean { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1780 | const focusedChildIndex = this._focusedChildIndex(); |
| 1781 | if (focusedChildIndex === -1) { |
| 1782 | if ((event.key === 'ArrowLeft' && !this._collapsed) || (event.key === 'ArrowRight' && this._collapsed)) { |
| 1783 | this._setCollapsed(!this._collapsed); |
| 1784 | return true; |
| 1785 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1786 | } |
| 1787 | return super.maybeHandleOnKeyDown(event); |
| 1788 | } |
| 1789 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1790 | toMessageElement(): HTMLElement { |
| 1791 | let element: HTMLElement|null = this._element || null; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1792 | if (!element) { |
| 1793 | element = super.toMessageElement(); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1794 | const iconType = this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1795 | this._expandGroupIcon = UI.Icon.Icon.create(iconType, 'expand-group-icon'); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 1796 | // Intercept focus to avoid highlight on click. |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1797 | this.contentElement().tabIndex = -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1798 | if (this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1799 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1800 | } else { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1801 | element.insertBefore(this._expandGroupIcon, this._contentElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1802 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1803 | element.addEventListener('click', () => this._setCollapsed(!this._collapsed)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1804 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1805 | return element; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1806 | } |
| 1807 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1808 | _showRepeatCountElement(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1809 | super._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1810 | if (this._repeatCountElement && this._expandGroupIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1811 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1812 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1813 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1814 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1815 | |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1816 | export class ConsoleCommand extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1817 | _formattedCommand: HTMLElement|null; |
| 1818 | |
| 1819 | constructor( |
| 1820 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1821 | onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1822 | super(consoleMessage, linkifier, nestingLevel, onResize); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1823 | this._formattedCommand = null; |
| 1824 | } |
| 1825 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1826 | contentElement(): HTMLElement { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1827 | const contentElement = this.getContentElement(); |
| 1828 | if (contentElement) { |
| 1829 | return contentElement; |
| 1830 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1831 | const newContentElement = (document.createElement('div') as HTMLElement); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1832 | this.setContentElement(newContentElement); |
| 1833 | newContentElement.classList.add('console-user-command'); |
| 1834 | const icon = UI.Icon.Icon.create('smallicon-user-command', 'command-result-icon'); |
| 1835 | newContentElement.appendChild(icon); |
| 1836 | |
| 1837 | elementToMessage.set(newContentElement, this); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1838 | this._formattedCommand = (document.createElement('span') as HTMLElement); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1839 | this._formattedCommand.classList.add('source-code'); |
| 1840 | this._formattedCommand.textContent = Platform.StringUtilities.replaceControlCharacters(this.text); |
| 1841 | newContentElement.appendChild(this._formattedCommand); |
| 1842 | |
| 1843 | if (this._formattedCommand.textContent.length < MaxLengthToIgnoreHighlighter) { |
Andres Olivares | f59e6de | 2021-02-18 13:10:25 | [diff] [blame] | 1844 | const javascriptSyntaxHighlighter = new TextEditor.SyntaxHighlighter.SyntaxHighlighter('text/javascript', true); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1845 | javascriptSyntaxHighlighter.syntaxHighlightNode(this._formattedCommand).then(this._updateSearch.bind(this)); |
| 1846 | } else { |
| 1847 | this._updateSearch(); |
| 1848 | } |
| 1849 | |
| 1850 | this.updateTimestamp(); |
| 1851 | return newContentElement; |
| 1852 | } |
| 1853 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1854 | _updateSearch(): void { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1855 | this.setSearchRegex(this.searchRegex()); |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | export class ConsoleCommandResult extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1860 | contentElement(): HTMLElement { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1861 | const element = super.contentElement(); |
| 1862 | if (!element.classList.contains('console-user-command-result')) { |
| 1863 | element.classList.add('console-user-command-result'); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1864 | if (this.consoleMessage().level === Protocol.Log.LogEntryLevel.Info) { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1865 | const icon = UI.Icon.Icon.create('smallicon-command-result', 'command-result-icon'); |
| 1866 | element.insertBefore(icon, element.firstChild); |
| 1867 | } |
| 1868 | } |
| 1869 | return element; |
| 1870 | } |
| 1871 | } |
| 1872 | |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1873 | export class ConsoleTableMessageView extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1874 | _dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<unknown>|null; |
| 1875 | |
| 1876 | constructor( |
| 1877 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1878 | onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1879 | super(consoleMessage, linkifier, nestingLevel, onResize); |
Tim van der Lippe | eb876c6 | 2021-05-14 15:02:11 | [diff] [blame] | 1880 | console.assert(consoleMessage.type === Protocol.Runtime.ConsoleAPICalledEventType.Table); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1881 | this._dataGrid = null; |
| 1882 | } |
| 1883 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1884 | wasShown(): void { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1885 | if (this._dataGrid) { |
| 1886 | this._dataGrid.updateWidths(); |
| 1887 | } |
| 1888 | super.wasShown(); |
| 1889 | } |
| 1890 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1891 | onResize(): void { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1892 | if (!this.isVisible()) { |
| 1893 | return; |
| 1894 | } |
| 1895 | if (this._dataGrid) { |
| 1896 | this._dataGrid.onResize(); |
| 1897 | } |
| 1898 | } |
| 1899 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1900 | contentElement(): HTMLElement { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1901 | const contentElement = this.getContentElement(); |
| 1902 | if (contentElement) { |
| 1903 | return contentElement; |
| 1904 | } |
| 1905 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1906 | const newContentElement = (document.createElement('div') as HTMLElement); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1907 | newContentElement.classList.add('console-message'); |
| 1908 | if (this._messageLevelIcon) { |
| 1909 | newContentElement.appendChild(this._messageLevelIcon); |
| 1910 | } |
| 1911 | this.setContentElement(newContentElement); |
| 1912 | |
| 1913 | newContentElement.appendChild(this._buildTableMessage()); |
| 1914 | this.updateTimestamp(); |
| 1915 | return newContentElement; |
| 1916 | } |
| 1917 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1918 | _buildTableMessage(): HTMLElement { |
| 1919 | const formattedMessage = (document.createElement('span') as HTMLElement); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1920 | formattedMessage.classList.add('source-code'); |
| 1921 | this._anchorElement = this._buildMessageAnchor(); |
| 1922 | if (this._anchorElement) { |
| 1923 | formattedMessage.appendChild(this._anchorElement); |
| 1924 | } |
| 1925 | |
| 1926 | const table = this._message.parameters && this._message.parameters.length ? this._message.parameters[0] : null; |
| 1927 | if (!table) { |
| 1928 | return this._buildMessage(); |
| 1929 | } |
| 1930 | const actualTable = parameterToRemoteObject(this._message.runtimeModel())(table); |
| 1931 | if (!actualTable || !actualTable.preview) { |
| 1932 | return this._buildMessage(); |
| 1933 | } |
| 1934 | |
| 1935 | const rawValueColumnSymbol = Symbol('rawValueColumn'); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1936 | const columnNames: (string|symbol)[] = []; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1937 | const preview = actualTable.preview; |
| 1938 | const rows = []; |
| 1939 | for (let i = 0; i < preview.properties.length; ++i) { |
| 1940 | const rowProperty = preview.properties[i]; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1941 | let rowSubProperties: Protocol.Runtime.PropertyPreview[]; |
Sigurd Schneider | b393a43 | 2020-11-06 12:08:21 | [diff] [blame] | 1942 | if (rowProperty.valuePreview && rowProperty.valuePreview.properties.length) { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1943 | rowSubProperties = rowProperty.valuePreview.properties; |
| 1944 | } else if (rowProperty.value) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1945 | rowSubProperties = |
| 1946 | [{name: rawValueColumnSymbol as unknown as string, type: rowProperty.type, value: rowProperty.value}]; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1947 | } else { |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1951 | const rowValue = new Map<string|symbol, HTMLElement>(); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1952 | const maxColumnsToRender = 20; |
| 1953 | for (let j = 0; j < rowSubProperties.length; ++j) { |
| 1954 | const cellProperty = rowSubProperties[j]; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1955 | let columnRendered: true|boolean = columnNames.indexOf(cellProperty.name) !== -1; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1956 | if (!columnRendered) { |
| 1957 | if (columnNames.length === maxColumnsToRender) { |
| 1958 | continue; |
| 1959 | } |
| 1960 | columnRendered = true; |
| 1961 | columnNames.push(cellProperty.name); |
| 1962 | } |
| 1963 | |
| 1964 | if (columnRendered) { |
| 1965 | const cellElement = |
| 1966 | this._renderPropertyPreviewOrAccessor(actualTable, cellProperty, [rowProperty, cellProperty]); |
| 1967 | cellElement.classList.add('console-message-nowrap-below'); |
| 1968 | rowValue.set(cellProperty.name, cellElement); |
| 1969 | } |
| 1970 | } |
| 1971 | rows.push({rowName: rowProperty.name, rowValue}); |
| 1972 | } |
| 1973 | |
| 1974 | const flatValues = []; |
| 1975 | for (const {rowName, rowValue} of rows) { |
| 1976 | flatValues.push(rowName); |
| 1977 | for (let j = 0; j < columnNames.length; ++j) { |
| 1978 | flatValues.push(rowValue.get(columnNames[j])); |
| 1979 | } |
| 1980 | } |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1981 | columnNames.unshift(i18nString(UIStrings.index)); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1982 | const columnDisplayNames = |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1983 | columnNames.map(name => name === rawValueColumnSymbol ? i18nString(UIStrings.value) : name.toString()); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1984 | |
| 1985 | if (flatValues.length) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1986 | this._dataGrid = DataGrid.SortableDataGrid.SortableDataGrid.create( |
| 1987 | columnDisplayNames, flatValues, i18nString(UIStrings.console)); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1988 | if (this._dataGrid) { |
| 1989 | this._dataGrid.setStriped(true); |
| 1990 | this._dataGrid.setFocusable(false); |
| 1991 | |
| 1992 | const formattedResult = document.createElement('span'); |
| 1993 | formattedResult.classList.add('console-message-text'); |
| 1994 | const tableElement = formattedResult.createChild('div', 'console-message-formatted-table'); |
| 1995 | const dataGridContainer = tableElement.createChild('span'); |
| 1996 | tableElement.appendChild(this._formatParameter(actualTable, true, false)); |
| 1997 | dataGridContainer.appendChild(this._dataGrid.element); |
| 1998 | formattedMessage.appendChild(formattedResult); |
| 1999 | this._dataGrid.renderInline(); |
| 2000 | } |
| 2001 | } |
| 2002 | return formattedMessage; |
| 2003 | } |
| 2004 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2005 | approximateFastHeight(): number { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 2006 | const table = this._message.parameters && this._message.parameters[0]; |
| 2007 | if (table && typeof table !== 'string' && table.preview) { |
| 2008 | return defaultConsoleRowHeight * table.preview.properties.length; |
| 2009 | } |
| 2010 | return defaultConsoleRowHeight; |
| 2011 | } |
| 2012 | } |
| 2013 | |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 2014 | /** |
| 2015 | * The maximum length before strings are considered too long for syntax highlighting. |
| 2016 | * @const |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 2017 | */ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2018 | const MaxLengthToIgnoreHighlighter: number = 10000; |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 2019 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2020 | /** |
| 2021 | * @const |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2022 | */ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2023 | export const MaxLengthForLinks: number = 40; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2024 | |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 2025 | let maxTokenizableStringLength = 10000; |
| 2026 | let longStringVisibleLength = 5000; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 2027 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2028 | export const getMaxTokenizableStringLength = (): number => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 2029 | return maxTokenizableStringLength; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 2030 | }; |
| 2031 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2032 | export const setMaxTokenizableStringLength = (length: number): void => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 2033 | maxTokenizableStringLength = length; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 2034 | }; |
| 2035 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2036 | export const getLongStringVisibleLength = (): number => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 2037 | return longStringVisibleLength; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 2038 | }; |
| 2039 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 2040 | export const setLongStringVisibleLength = (length: number): void => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 2041 | longStringVisibleLength = length; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 2042 | }; |