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