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 | 9b2f871 | 2020-02-12 17:46:22 | [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'; |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 40 | import * as i18n from '../i18n/i18n.js'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 41 | import * as ObjectUI from '../object_ui/object_ui.js'; |
Tim van der Lippe | 93b57c3 | 2020-02-20 17:38:44 | [diff] [blame] | 42 | import * as Platform from '../platform/platform.js'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 43 | import * as SDK from '../sdk/sdk.js'; |
Andres Olivares | f59e6de | 2021-02-18 13:10:25 | [diff] [blame] | 44 | import * as TextEditor from '../text_editor/text_editor.js'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 45 | import * as TextUtils from '../text_utils/text_utils.js'; |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 46 | import * as ThemeSupport from '../theme_support/theme_support.js'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 47 | import * as UI from '../ui/ui.js'; |
| 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 | }; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 160 | const str_ = i18n.i18n.registerUIStrings('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': |
| 581 | case 'weakmap': |
| 582 | case 'weakset': |
Benedikt Meurer | dead315 | 2020-12-07 08:43:40 | [diff] [blame] | 583 | case 'webassemblymemory': |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 584 | element = this._formatParameterAsObject(output, includePreview); |
| 585 | break; |
| 586 | case 'node': |
| 587 | element = output.isNode() ? this._formatParameterAsNode(output) : this._formatParameterAsObject(output, false); |
| 588 | break; |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 589 | case 'trustedtype': |
| 590 | element = this._formatParameterAsObject(output, false); |
| 591 | break; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 592 | case 'string': |
| 593 | element = this._formatParameterAsString(output); |
| 594 | break; |
| 595 | case 'boolean': |
| 596 | case 'date': |
| 597 | case 'null': |
| 598 | case 'number': |
| 599 | case 'regexp': |
| 600 | case 'symbol': |
| 601 | case 'undefined': |
| 602 | case 'bigint': |
| 603 | element = this._formatParameterAsValue(output); |
| 604 | break; |
| 605 | default: |
| 606 | element = this._formatParameterAsValue(output); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 607 | console.error(`Tried to format remote object of unknown type ${outputType}.`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 608 | } |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 609 | element.classList.add(`object-value-${outputType}`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 610 | element.classList.add('source-code'); |
| 611 | return element; |
| 612 | } |
| 613 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 614 | _formatParameterAsValue(obj: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 615 | const result = (document.createElement('span') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 616 | const description = obj.description || ''; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 617 | if (description.length > getMaxTokenizableStringLength()) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 618 | const propertyValue = new ObjectUI.ObjectPropertiesSection.ExpandableTextPropertyValue( |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 619 | document.createElement('span'), description, getLongStringVisibleLength()); |
Connor Moody | 1a5c0d3 | 2019-12-19 07:23:36 | [diff] [blame] | 620 | result.appendChild(propertyValue.element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 621 | } else { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 622 | UI.UIUtils.createTextChild(result, description); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 623 | } |
| 624 | if (obj.objectId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 625 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, obj), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 626 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 627 | return result; |
| 628 | } |
| 629 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 630 | _formatParameterAsTrustedType(obj: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 631 | const result = (document.createElement('span') as HTMLElement); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 632 | const trustedContentSpan = document.createElement('span'); |
| 633 | trustedContentSpan.appendChild(this._formatParameterAsString(obj)); |
| 634 | trustedContentSpan.classList.add('object-value-string'); |
Alfonso Castaño | dfe8ca3 | 2020-10-29 13:03:09 | [diff] [blame] | 635 | UI.UIUtils.createTextChild(result, `${obj.className} `); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 636 | result.appendChild(trustedContentSpan); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 637 | return result; |
| 638 | } |
| 639 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 640 | _formatParameterAsObject(obj: SDK.RemoteObject.RemoteObject, includePreview?: boolean): HTMLElement { |
| 641 | const titleElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 642 | titleElement.classList.add('console-object'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 643 | if (includePreview && obj.preview) { |
| 644 | titleElement.classList.add('console-object-preview'); |
| 645 | this._previewFormatter.appendObjectPreview(titleElement, obj.preview, false /* isEntry */); |
| 646 | } else if (obj.type === 'function') { |
| 647 | const functionElement = titleElement.createChild('span'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 648 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.formatObjectAsFunction(obj, functionElement, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 649 | titleElement.classList.add('object-value-function'); |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 650 | } else if (obj.subtype === 'trustedtype') { |
| 651 | titleElement.appendChild(this._formatParameterAsTrustedType(obj)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 652 | } else { |
Sigurd Schneider | 23c5297 | 2020-10-13 09:31:14 | [diff] [blame] | 653 | UI.UIUtils.createTextChild(titleElement, obj.description || ''); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 654 | } |
| 655 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 656 | if (!obj.hasChildren || obj.customPreview()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 657 | return titleElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 658 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 659 | |
| 660 | const note = titleElement.createChild('span', 'object-state-note info-note'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 661 | if (this._message.type === SDK.ConsoleModel.MessageType.QueryObjectResult) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 662 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.thisValueWillNotBeCollectedUntil)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 663 | } else { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 664 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.thisValueWasEvaluatedUponFirst)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 665 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 666 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 667 | const section = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection(obj, titleElement, this._linkifier); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 668 | section.element.classList.add('console-view-object-properties-section'); |
| 669 | section.enableContextMenu(); |
Erik Luo | cc14b81 | 2018-11-03 01:33:09 | [diff] [blame] | 670 | section.setShowSelectionOnKeyboardFocus(true, true); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 671 | this._selectableChildren.push(section); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 672 | section.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 673 | section.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 674 | section.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 675 | return section.element; |
| 676 | } |
| 677 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 678 | _formatParameterAsFunction(func: SDK.RemoteObject.RemoteObject, includePreview?: boolean): HTMLElement { |
| 679 | const result = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 680 | SDK.RemoteObject.RemoteFunction.objectAsFunction(func).targetFunction().then(formatTargetFunction.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 681 | return result; |
| 682 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 683 | function formatTargetFunction(this: ConsoleViewMessage, targetFunction: SDK.RemoteObject.RemoteObject): void { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 684 | const functionElement = document.createElement('span'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 685 | const promise = ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.formatObjectAsFunction( |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 686 | targetFunction, functionElement, true, includePreview); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 687 | result.appendChild(functionElement); |
| 688 | if (targetFunction !== func) { |
| 689 | const note = result.createChild('span', 'object-info-state-note'); |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 690 | UI.Tooltip.Tooltip.install(note, i18nString(UIStrings.functionWasResolvedFromBound)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 691 | } |
| 692 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, targetFunction), false); |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 693 | promise.then(() => this._formattedParameterAsFunctionForTest()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 697 | _formattedParameterAsFunctionForTest(): void { |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 698 | } |
| 699 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 700 | _contextMenuEventFired(obj: SDK.RemoteObject.RemoteObject, event: Event): void { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 701 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 702 | contextMenu.appendApplicableItems(obj); |
| 703 | contextMenu.show(); |
| 704 | } |
| 705 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 706 | _renderPropertyPreviewOrAccessor( |
| 707 | object: SDK.RemoteObject.RemoteObject|null, property: Protocol.Runtime.PropertyPreview, propertyPath: { |
| 708 | name: (string|symbol), |
| 709 | }[]): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 710 | if (property.type === 'accessor') { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 711 | return this._formatAsAccessorProperty(object, propertyPath.map(property => property.name.toString()), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 712 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 713 | return this._previewFormatter.renderPropertyPreview( |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 714 | property.type, 'subtype' in property ? property.subtype : undefined, null, property.value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 715 | } |
| 716 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 717 | _formatParameterAsNode(remoteObject: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 718 | const result = document.createElement('span'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 719 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 720 | const domModel = remoteObject.runtimeModel().target().model(SDK.DOMModel.DOMModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 721 | if (!domModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 722 | return result; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 723 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 724 | domModel.pushObjectAsNodeToFrontend(remoteObject).then(async (node: SDK.DOMModel.DOMNode|null) => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 725 | if (!node) { |
| 726 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 727 | return; |
| 728 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 729 | const renderResult = await UI.UIUtils.Renderer.render((node as Object)); |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 730 | if (renderResult) { |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 731 | if (renderResult.tree) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 732 | this._selectableChildren.push(renderResult.tree); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 733 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 734 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 735 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
| 736 | } |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 737 | result.appendChild(renderResult.node); |
| 738 | } else { |
| 739 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 740 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 741 | this._formattedParameterAsNodeForTest(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 742 | }); |
| 743 | |
| 744 | return result; |
| 745 | } |
| 746 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 747 | _formattedParameterAsNodeForTest(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 748 | } |
| 749 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 750 | _formatParameterAsString(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
Benedikt Meurer | 62b49da | 2021-02-18 09:15:55 | [diff] [blame] | 751 | // Properly escape double quotes here, so users don't get surprised |
| 752 | // when they copy strings from the console (https://crbug.com/1178530). |
| 753 | const description = output.description ?? ''; |
| 754 | const text = JSON.stringify(description); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 755 | const result = (document.createElement('span') as HTMLElement); |
Benedikt Meurer | 62b49da | 2021-02-18 09:15:55 | [diff] [blame] | 756 | result.appendChild(this._linkifyStringAsFragment(text)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 757 | return result; |
| 758 | } |
| 759 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 760 | _formatParameterAsError(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
| 761 | const result = (document.createElement('span') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 762 | const errorSpan = this._tryFormatAsError(output.description || ''); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 763 | result.appendChild(errorSpan ? errorSpan : this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 764 | return result; |
| 765 | } |
| 766 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 767 | _formatAsArrayEntry(output: SDK.RemoteObject.RemoteObject): HTMLElement { |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 768 | return this._previewFormatter.renderPropertyPreview( |
| 769 | output.type, output.subtype, output.className, output.description); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 770 | } |
| 771 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 772 | _formatAsAccessorProperty(object: SDK.RemoteObject.RemoteObject|null, propertyPath: string[], isArrayEntry: boolean): |
| 773 | HTMLElement { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 774 | const rootElement = |
| 775 | ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement.createRemoteObjectAccessorPropertySpan( |
| 776 | object, propertyPath, onInvokeGetterClick.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 777 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 778 | function onInvokeGetterClick(this: ConsoleViewMessage, result: SDK.RemoteObject.CallFunctionResult): void { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 779 | const wasThrown = result.wasThrown; |
| 780 | const object = result.object; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 781 | if (!object) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 782 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 783 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 784 | rootElement.removeChildren(); |
| 785 | if (wasThrown) { |
| 786 | const element = rootElement.createChild('span'); |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 787 | element.textContent = i18nString(UIStrings.exception); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 788 | UI.Tooltip.Tooltip.install(element, (object.description as string)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 789 | } else if (isArrayEntry) { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 790 | rootElement.appendChild(this._formatAsArrayEntry(object)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 791 | } else { |
| 792 | // Make a PropertyPreview from the RemoteObject similar to the backend logic. |
| 793 | const maxLength = 100; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 794 | const type = object.type; |
| 795 | const subtype = object.subtype; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 796 | let description = ''; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 797 | if (type !== 'function' && object.description) { |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 798 | if (type === 'string' || subtype === 'regexp' || subtype === 'trustedtype') { |
Tim van der Lippe | 213266c | 2021-01-18 15:48:31 | [diff] [blame] | 799 | description = Platform.StringUtilities.trimMiddle(object.description, maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 800 | } else { |
Tim van der Lippe | 3cc3af3 | 2021-01-19 14:25:26 | [diff] [blame] | 801 | description = Platform.StringUtilities.trimEndWithMaxLength(object.description, maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 802 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 803 | } |
Alfonso Castaño | 20d22cd | 2020-10-28 16:23:58 | [diff] [blame] | 804 | rootElement.appendChild( |
| 805 | this._previewFormatter.renderPropertyPreview(type, subtype, object.className, description)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
| 809 | return rootElement; |
| 810 | } |
| 811 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 812 | _formatWithSubstitutionString( |
| 813 | format: string, parameters: SDK.RemoteObject.RemoteObject[], formattedResult: HTMLElement): { |
| 814 | formattedResult: Element, |
| 815 | unusedSubstitutions: ArrayLike<SDK.RemoteObject.RemoteObject>|null, |
| 816 | } { |
| 817 | function parameterFormatter( |
| 818 | this: ConsoleViewMessage, force: boolean, includePreview: boolean, |
| 819 | obj?: string|SDK.RemoteObject.RemoteObject): string|HTMLElement|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 820 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 821 | return this._formatParameter(obj, force, includePreview); |
| 822 | } |
| 823 | return stringFormatter(obj); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 824 | } |
| 825 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 826 | function stringFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 827 | if (obj === undefined) { |
| 828 | return undefined; |
| 829 | } |
| 830 | if (typeof obj === 'string') { |
| 831 | return obj; |
| 832 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 833 | return obj.description; |
| 834 | } |
| 835 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 836 | function floatFormatter(obj?: string|SDK.RemoteObject.RemoteObject): number|string|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 837 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 838 | if (typeof obj.value !== 'number') { |
| 839 | return 'NaN'; |
| 840 | } |
| 841 | return obj.value; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 842 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 843 | return undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 844 | } |
| 845 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 846 | function integerFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|number|undefined { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 847 | if (obj instanceof SDK.RemoteObject.RemoteObject) { |
| 848 | if (obj.type === 'bigint') { |
| 849 | return obj.description; |
| 850 | } |
| 851 | if (typeof obj.value !== 'number') { |
| 852 | return 'NaN'; |
| 853 | } |
| 854 | return Math.floor(obj.value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 855 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 856 | return undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 857 | } |
| 858 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 859 | function bypassFormatter(obj?: string|SDK.RemoteObject.RemoteObject): Node|string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 860 | return (obj instanceof Node) ? obj : ''; |
| 861 | } |
| 862 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 863 | let currentStyle: Map<string, {value: string, priority: string}>|null = null; |
| 864 | function styleFormatter(obj?: string|SDK.RemoteObject.RemoteObject): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 865 | currentStyle = new Map(); |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 866 | const buffer = document.createElement('span'); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 867 | if (obj === undefined) { |
| 868 | return; |
| 869 | } |
| 870 | if (typeof obj === 'string' || !obj.description) { |
| 871 | return; |
| 872 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 873 | buffer.setAttribute('style', obj.description); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 874 | for (const property of buffer.style) { |
Mathias Bynens | 5165a7a | 2020-06-10 05:51:43 | [diff] [blame] | 875 | if (isAllowedProperty(property)) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 876 | const info = { |
| 877 | value: buffer.style.getPropertyValue(property), |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 878 | priority: buffer.style.getPropertyPriority(property), |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 879 | }; |
| 880 | currentStyle.set(property, info); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 881 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 885 | function isAllowedProperty(property: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 886 | // Make sure that allowed properties do not interfere with link visibility. |
| 887 | const prefixes = [ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 888 | 'background', |
| 889 | 'border', |
| 890 | 'color', |
| 891 | 'font', |
| 892 | 'line', |
| 893 | 'margin', |
| 894 | 'padding', |
| 895 | 'text', |
| 896 | '-webkit-background', |
| 897 | '-webkit-border', |
| 898 | '-webkit-font', |
| 899 | '-webkit-margin', |
| 900 | '-webkit-padding', |
| 901 | '-webkit-text', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 902 | ]; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 903 | for (const prefix of prefixes) { |
| 904 | if (property.startsWith(prefix)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 905 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 906 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 907 | } |
| 908 | return false; |
| 909 | } |
| 910 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 911 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration) |
| 912 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 913 | const formatters: Record<string, Platform.StringUtilities.FormatterFunction<any>> = {}; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 914 | // Firebug uses %o for formatting objects. |
| 915 | formatters.o = parameterFormatter.bind(this, false /* force */, true /* includePreview */); |
| 916 | formatters.s = stringFormatter; |
| 917 | formatters.f = floatFormatter; |
| 918 | // Firebug allows both %i and %d for formatting integers. |
| 919 | formatters.i = integerFormatter; |
| 920 | formatters.d = integerFormatter; |
| 921 | |
| 922 | // Firebug uses %c for styling the message. |
| 923 | formatters.c = styleFormatter; |
| 924 | |
| 925 | // Support %O to force object formatting, instead of the type-based %o formatting. |
| 926 | formatters.O = parameterFormatter.bind(this, true /* force */, false /* includePreview */); |
| 927 | |
| 928 | formatters._ = bypassFormatter; |
| 929 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 930 | function append(this: ConsoleViewMessage, a: HTMLElement, b?: string|Node): HTMLElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 931 | if (b instanceof Node) { |
| 932 | a.appendChild(b); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 933 | return a; |
| 934 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 935 | if (typeof b === 'undefined') { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 936 | return a; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 937 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 938 | if (!currentStyle) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 939 | a.appendChild(this._linkifyStringAsFragment(String(b))); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 940 | return a; |
| 941 | } |
| 942 | const lines = String(b).split('\n'); |
| 943 | for (let i = 0; i < lines.length; i++) { |
| 944 | const line = lines[i]; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 945 | const lineFragment = this._linkifyStringAsFragment(line); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 946 | const wrapper = (document.createElement('span') as HTMLElement); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 947 | wrapper.style.setProperty('contain', 'paint'); |
| 948 | wrapper.style.setProperty('display', 'inline-block'); |
| 949 | wrapper.style.setProperty('max-width', '100%'); |
| 950 | wrapper.appendChild(lineFragment); |
| 951 | applyCurrentStyle(wrapper); |
| 952 | for (const child of wrapper.children) { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 953 | if (child.classList.contains('devtools-link') && child instanceof HTMLElement) { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 954 | this._applyForcedVisibleStyle(child); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 955 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 956 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 957 | a.appendChild(wrapper); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 958 | if (i < lines.length - 1) { |
Sigurd Schneider | 53f3352 | 2020-10-08 15:00:49 | [diff] [blame] | 959 | a.appendChild(document.createElement('br')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 960 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 961 | } |
| 962 | return a; |
| 963 | } |
| 964 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 965 | function applyCurrentStyle(element: HTMLElement): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 966 | if (!currentStyle) { |
| 967 | return; |
| 968 | } |
| 969 | for (const [property, {value, priority}] of currentStyle.entries()) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 970 | element.style.setProperty((property as string), value, priority); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 971 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 972 | } |
| 973 | |
Tim van der Lippe | 93b57c3 | 2020-02-20 17:38:44 | [diff] [blame] | 974 | // Platform.StringUtilities.format does treat formattedResult like a Builder, result is an object. |
| 975 | return Platform.StringUtilities.format(format, parameters, formatters, formattedResult, append.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 976 | } |
| 977 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 978 | _applyForcedVisibleStyle(element: HTMLElement): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 979 | element.style.setProperty('-webkit-text-stroke', '0', 'important'); |
| 980 | element.style.setProperty('text-decoration', 'underline', 'important'); |
| 981 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 982 | const themedColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 983 | 'rgb(33%, 33%, 33%)', ThemeSupport.ThemeSupport.ColorUsage.Foreground); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 984 | element.style.setProperty('color', themedColor, 'important'); |
| 985 | |
| 986 | let backgroundColor = 'hsl(0, 0%, 100%)'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 987 | if (this._message.level === SDK.ConsoleModel.MessageLevel.Error) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 988 | backgroundColor = 'hsl(0, 100%, 97%)'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 989 | } else if (this._message.level === SDK.ConsoleModel.MessageLevel.Warning || this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 990 | backgroundColor = 'hsl(50, 100%, 95%)'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 991 | } |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 992 | const themedBackgroundColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 993 | backgroundColor, ThemeSupport.ThemeSupport.ColorUsage.Background); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 994 | element.style.setProperty('background-color', themedBackgroundColor, 'important'); |
| 995 | } |
| 996 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 997 | matchesFilterRegex(regexObject: RegExp): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 998 | regexObject.lastIndex = 0; |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 999 | const contentElement = this.contentElement(); |
| 1000 | const anchorText = this._anchorElement ? this._anchorElement.deepTextContent() : ''; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1001 | return (Boolean(anchorText) && regexObject.test(anchorText.trim())) || |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 1002 | regexObject.test(contentElement.deepTextContent().slice(anchorText.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1003 | } |
| 1004 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1005 | matchesFilterText(filter: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1006 | const text = this.contentElement().deepTextContent(); |
| 1007 | return text.toLowerCase().includes(filter.toLowerCase()); |
| 1008 | } |
| 1009 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1010 | updateTimestamp(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1011 | if (!this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1012 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1013 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1014 | |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 1015 | if (Common.Settings.Settings.instance().moduleSetting('consoleTimestampsEnabled').get()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1016 | if (!this._timestampElement) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1017 | this._timestampElement = (document.createElement('span') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1018 | this._timestampElement.classList.add('console-timestamp'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1019 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1020 | this._timestampElement.textContent = UI.UIUtils.formatTimestamp(this._message.timestamp, false) + ' '; |
Tim van der Lippe | 70842f3 | 2020-11-23 16:56:57 | [diff] [blame] | 1021 | UI.Tooltip.Tooltip.install(this._timestampElement, UI.UIUtils.formatTimestamp(this._message.timestamp, true)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1022 | this._contentElement.insertBefore(this._timestampElement, this._contentElement.firstChild); |
| 1023 | } else if (this._timestampElement) { |
| 1024 | this._timestampElement.remove(); |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 1025 | this._timestampElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1026 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1027 | } |
| 1028 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1029 | nestingLevel(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1030 | return this._nestingLevel; |
| 1031 | } |
| 1032 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1033 | setInSimilarGroup(inSimilarGroup: boolean, isLast?: boolean): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1034 | this._inSimilarGroup = inSimilarGroup; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1035 | this._lastInSimilarGroup = inSimilarGroup && Boolean(isLast); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1036 | if (this._similarGroupMarker && !inSimilarGroup) { |
| 1037 | this._similarGroupMarker.remove(); |
| 1038 | this._similarGroupMarker = null; |
| 1039 | } else if (this._element && !this._similarGroupMarker && inSimilarGroup) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1040 | this._similarGroupMarker = (document.createElement('div') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1041 | this._similarGroupMarker.classList.add('nesting-level-marker'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1042 | this._element.insertBefore(this._similarGroupMarker, this._element.firstChild); |
| 1043 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1044 | } |
| 1045 | } |
| 1046 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1047 | isLastInSimilarGroup(): boolean { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1048 | return Boolean(this._inSimilarGroup) && Boolean(this._lastInSimilarGroup); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1049 | } |
| 1050 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1051 | resetCloseGroupDecorationCount(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1052 | if (!this._closeGroupDecorationCount) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1053 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1054 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1055 | this._closeGroupDecorationCount = 0; |
| 1056 | this._updateCloseGroupDecorations(); |
| 1057 | } |
| 1058 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1059 | incrementCloseGroupDecorationCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1060 | ++this._closeGroupDecorationCount; |
| 1061 | this._updateCloseGroupDecorations(); |
| 1062 | } |
| 1063 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1064 | _updateCloseGroupDecorations(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1065 | if (!this._nestingLevelMarkers) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1066 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1067 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1068 | for (let i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
| 1069 | const marker = this._nestingLevelMarkers[i]; |
| 1070 | marker.classList.toggle('group-closed', n - i <= this._closeGroupDecorationCount); |
| 1071 | } |
| 1072 | } |
| 1073 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1074 | _focusedChildIndex(): number { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1075 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1076 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1077 | } |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1078 | return this._selectableChildren.findIndex(child => child.element.hasFocus()); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1079 | } |
| 1080 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1081 | _onKeyDown(event: KeyboardEvent): void { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1082 | if (UI.UIUtils.isEditing() || !this._element || !this._element.hasFocus() || this._element.hasSelection()) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1083 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1084 | } |
| 1085 | if (this.maybeHandleOnKeyDown(event)) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1086 | event.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1087 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1088 | } |
| 1089 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1090 | maybeHandleOnKeyDown(event: KeyboardEvent): boolean { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1091 | // Handle trace expansion. |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1092 | const focusedChildIndex = this._focusedChildIndex(); |
| 1093 | const isWrapperFocused = focusedChildIndex === -1; |
| 1094 | if (this._expandTrace && isWrapperFocused) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1095 | if ((event.key === 'ArrowLeft' && this._traceExpanded) || (event.key === 'ArrowRight' && !this._traceExpanded)) { |
| 1096 | this._expandTrace(!this._traceExpanded); |
| 1097 | return true; |
| 1098 | } |
| 1099 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1100 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1101 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1102 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1103 | |
| 1104 | if (event.key === 'ArrowLeft') { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1105 | this._element && this._element.focus(); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1106 | return true; |
| 1107 | } |
| 1108 | if (event.key === 'ArrowRight') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1109 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1110 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1111 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1112 | } |
| 1113 | if (event.key === 'ArrowUp') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1114 | const firstVisibleChild = this._nearestVisibleChild(0); |
| 1115 | if (this._selectableChildren[focusedChildIndex] === firstVisibleChild && firstVisibleChild) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1116 | this._element && this._element.focus(); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1117 | return true; |
Mathias Bynens | f06e8c0 | 2020-02-28 13:58:28 | [diff] [blame] | 1118 | } |
| 1119 | if (this._selectNearestVisibleChild(focusedChildIndex - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1120 | return true; |
| 1121 | } |
| 1122 | } |
| 1123 | if (event.key === 'ArrowDown') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1124 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1125 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1126 | } |
| 1127 | if (!isWrapperFocused && this._selectNearestVisibleChild(focusedChildIndex + 1)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1128 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1129 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1130 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1131 | return false; |
| 1132 | } |
| 1133 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1134 | _selectNearestVisibleChild(fromIndex: number, backwards?: boolean): boolean { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1135 | const nearestChild = this._nearestVisibleChild(fromIndex, backwards); |
| 1136 | if (nearestChild) { |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1137 | nearestChild.forceSelect(); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1138 | return true; |
| 1139 | } |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1143 | _nearestVisibleChild(fromIndex: number, backwards?: boolean): { |
| 1144 | element: Element, |
| 1145 | forceSelect: () => void, |
| 1146 | }|null { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1147 | const childCount = this._selectableChildren.length; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1148 | if (fromIndex < 0 || fromIndex >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1149 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1150 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1151 | const direction = backwards ? -1 : 1; |
| 1152 | let index = fromIndex; |
| 1153 | |
| 1154 | while (!this._selectableChildren[index].element.offsetParent) { |
| 1155 | index += direction; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1156 | if (index < 0 || index >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1157 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1158 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1159 | } |
| 1160 | return this._selectableChildren[index]; |
| 1161 | } |
| 1162 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1163 | focusLastChildOrSelf(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1164 | if (this._element && !this._selectNearestVisibleChild(this._selectableChildren.length - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1165 | this._element.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1166 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1167 | } |
| 1168 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1169 | setContentElement(element: HTMLElement): void { |
Sigurd Schneider | b2953b2 | 2020-10-09 09:30:15 | [diff] [blame] | 1170 | console.assert(!this._contentElement, 'Cannot set content element twice'); |
| 1171 | this._contentElement = element; |
| 1172 | } |
| 1173 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1174 | getContentElement(): HTMLElement|null { |
Sigurd Schneider | b2953b2 | 2020-10-09 09:30:15 | [diff] [blame] | 1175 | return this._contentElement; |
| 1176 | } |
| 1177 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1178 | contentElement(): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1179 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1180 | return this._contentElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1181 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1182 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1183 | const contentElement = (document.createElement('div') as HTMLElement); |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 1184 | contentElement.classList.add('console-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1185 | if (this._messageLevelIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1186 | contentElement.appendChild(this._messageLevelIcon); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1187 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1188 | this._contentElement = contentElement; |
| 1189 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1190 | const runtimeModel = this._message.runtimeModel(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1191 | let formattedMessage; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1192 | const shouldIncludeTrace = Boolean(this._message.stackTrace) && |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1193 | (this._message.source === SDK.ConsoleModel.MessageSource.Network || |
| 1194 | this._message.source === SDK.ConsoleModel.MessageSource.Violation || |
| 1195 | this._message.level === SDK.ConsoleModel.MessageLevel.Error || |
| 1196 | this._message.level === SDK.ConsoleModel.MessageLevel.Warning || |
| 1197 | this._message.type === SDK.ConsoleModel.MessageType.Trace); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1198 | if (runtimeModel && shouldIncludeTrace) { |
| 1199 | formattedMessage = this._buildMessageWithStackTrace(runtimeModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1200 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1201 | formattedMessage = this._buildMessage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1202 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1203 | contentElement.appendChild(formattedMessage); |
| 1204 | |
| 1205 | this.updateTimestamp(); |
| 1206 | return this._contentElement; |
| 1207 | } |
| 1208 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1209 | toMessageElement(): HTMLElement { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1210 | if (this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1211 | return this._element; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1212 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1213 | this._element = (document.createElement('div') as HTMLElement); |
Pavel Feldman | db31091 | 2019-01-30 00:31:20 | [diff] [blame] | 1214 | this._element.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1215 | this._element.addEventListener('keydown', (this._onKeyDown.bind(this) as EventListener)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1216 | this.updateMessageElement(); |
| 1217 | return this._element; |
| 1218 | } |
| 1219 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1220 | updateMessageElement(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1221 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1222 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1223 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1224 | |
| 1225 | this._element.className = 'console-message-wrapper'; |
| 1226 | this._element.removeChildren(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1227 | if (this._message.isGroupStartMessage()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1228 | this._element.classList.add('console-group-title'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1229 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1230 | if (this._message.source === SDK.ConsoleModel.MessageSource.ConsoleAPI) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1231 | this._element.classList.add('console-from-api'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1232 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1233 | if (this._inSimilarGroup) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1234 | this._similarGroupMarker = (this._element.createChild('div', 'nesting-level-marker') as HTMLElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1235 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1236 | } |
| 1237 | |
| 1238 | this._nestingLevelMarkers = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1239 | for (let i = 0; i < this._nestingLevel; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1240 | this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-level-marker')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1241 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1242 | this._updateCloseGroupDecorations(); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1243 | elementToMessage.set(this._element, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1244 | |
| 1245 | switch (this._message.level) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1246 | case SDK.ConsoleModel.MessageLevel.Verbose: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1247 | this._element.classList.add('console-verbose-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | break; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1249 | case SDK.ConsoleModel.MessageLevel.Info: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1250 | this._element.classList.add('console-info-level'); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1251 | if (this._message.type === SDK.ConsoleModel.MessageType.System) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1252 | this._element.classList.add('console-system-type'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1253 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1254 | break; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1255 | case SDK.ConsoleModel.MessageLevel.Warning: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1256 | this._element.classList.add('console-warning-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1257 | break; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1258 | case SDK.ConsoleModel.MessageLevel.Error: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1259 | this._element.classList.add('console-error-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1260 | break; |
| 1261 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1262 | this._updateMessageLevelIcon(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1263 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1264 | this._element.classList.add('console-warning-level'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1265 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1266 | |
| 1267 | this._element.appendChild(this.contentElement()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1268 | if (this._repeatCount > 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1269 | this._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1270 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1271 | } |
| 1272 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1273 | _shouldRenderAsWarning(): boolean { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1274 | return (this._message.level === SDK.ConsoleModel.MessageLevel.Verbose || |
| 1275 | this._message.level === SDK.ConsoleModel.MessageLevel.Info) && |
| 1276 | (this._message.source === SDK.ConsoleModel.MessageSource.Violation || |
| 1277 | this._message.source === SDK.ConsoleModel.MessageSource.Deprecation || |
| 1278 | this._message.source === SDK.ConsoleModel.MessageSource.Intervention || |
| 1279 | this._message.source === SDK.ConsoleModel.MessageSource.Recommendation); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1280 | } |
| 1281 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1282 | _updateMessageLevelIcon(): void { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1283 | let iconType = ''; |
| 1284 | let accessibleName = ''; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1285 | if (this._message.level === SDK.ConsoleModel.MessageLevel.Warning) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1286 | iconType = 'smallicon-warning'; |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1287 | accessibleName = i18nString(UIStrings.warning); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1288 | } else if (this._message.level === SDK.ConsoleModel.MessageLevel.Error) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1289 | iconType = 'smallicon-error'; |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1290 | accessibleName = i18nString(UIStrings.error); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1291 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1292 | if (!this._messageLevelIcon) { |
| 1293 | if (!iconType) { |
| 1294 | return; |
| 1295 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1296 | this._messageLevelIcon = UI.Icon.Icon.create('', 'message-level-icon'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1297 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1298 | this._contentElement.insertBefore(this._messageLevelIcon, this._contentElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1299 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1300 | } |
| 1301 | this._messageLevelIcon.setIconType(iconType); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1302 | UI.ARIAUtils.setAccessibleName(this._messageLevelIcon, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1303 | } |
| 1304 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1305 | repeatCount(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1306 | return this._repeatCount || 1; |
| 1307 | } |
| 1308 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1309 | resetIncrementRepeatCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1310 | this._repeatCount = 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1311 | if (!this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1312 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1313 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1314 | |
| 1315 | this._repeatCountElement.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1316 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1317 | this._contentElement.classList.remove('repeated-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1318 | } |
Sigurd Schneider | 53e9863 | 2020-10-26 15:29:50 | [diff] [blame] | 1319 | this._repeatCountElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1320 | } |
| 1321 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1322 | incrementRepeatCount(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1323 | this._repeatCount++; |
| 1324 | this._showRepeatCountElement(); |
| 1325 | } |
| 1326 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1327 | setRepeatCount(repeatCount: number): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1328 | this._repeatCount = repeatCount; |
| 1329 | this._showRepeatCountElement(); |
| 1330 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1331 | _showRepeatCountElement(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1332 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1333 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1334 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1335 | |
| 1336 | if (!this._repeatCountElement) { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1337 | this._repeatCountElement = |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1338 | (document.createElement('span', {is: 'dt-small-bubble'}) as UI.UIUtils.DevToolsSmallBubble); |
Tim van der Lippe | ee954d4 | 2020-05-04 10:35:57 | [diff] [blame] | 1339 | this._repeatCountElement.classList.add('console-message-repeat-count'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1340 | switch (this._message.level) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1341 | case SDK.ConsoleModel.MessageLevel.Warning: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1342 | this._repeatCountElement.type = 'warning'; |
| 1343 | break; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1344 | case SDK.ConsoleModel.MessageLevel.Error: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1345 | this._repeatCountElement.type = 'error'; |
| 1346 | break; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1347 | case SDK.ConsoleModel.MessageLevel.Verbose: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1348 | this._repeatCountElement.type = 'verbose'; |
| 1349 | break; |
| 1350 | default: |
| 1351 | this._repeatCountElement.type = 'info'; |
| 1352 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1353 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1354 | this._repeatCountElement.type = 'warning'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1355 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1356 | |
| 1357 | this._element.insertBefore(this._repeatCountElement, this._contentElement); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1358 | this.contentElement().classList.add('repeated-message'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1359 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1360 | this._repeatCountElement.textContent = `${this._repeatCount}`; |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1361 | |
| 1362 | let accessibleName; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1363 | if (this._message.level === SDK.ConsoleModel.MessageLevel.Warning) { |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1364 | accessibleName = i18nString(UIStrings.warningS, {n: this._repeatCount}); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1365 | } else if (this._message.level === SDK.ConsoleModel.MessageLevel.Error) { |
Peter Marshall | 2bdcc64 | 2021-03-03 10:02:09 | [diff] [blame] | 1366 | accessibleName = i18nString(UIStrings.errorS, {n: this._repeatCount}); |
| 1367 | } else { |
| 1368 | accessibleName = i18nString(UIStrings.repeatS, {n: this._repeatCount}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1369 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1370 | UI.ARIAUtils.setAccessibleName(this._repeatCountElement, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1371 | } |
| 1372 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1373 | get text(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1374 | return this._message.messageText; |
| 1375 | } |
| 1376 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1377 | toExportString(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1378 | const lines = []; |
| 1379 | const nodes = this.contentElement().childTextNodes(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1380 | const messageContent = nodes.map(Components.Linkifier.Linkifier.untruncatedNodeText).join(''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1381 | for (let i = 0; i < this.repeatCount(); ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1382 | lines.push(messageContent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1383 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1384 | return lines.join('\n'); |
| 1385 | } |
| 1386 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1387 | setSearchRegex(regex: RegExp|null): void { |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1388 | if (this._searchHighlightNodeChanges && this._searchHighlightNodeChanges.length) { |
| 1389 | UI.UIUtils.revertDomChanges(this._searchHighlightNodeChanges); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1390 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1391 | this._searchRegex = regex; |
| 1392 | this._searchHighlightNodes = []; |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1393 | this._searchHighlightNodeChanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1394 | if (!this._searchRegex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1395 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1396 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1397 | |
| 1398 | const text = this.contentElement().deepTextContent(); |
| 1399 | let match; |
| 1400 | this._searchRegex.lastIndex = 0; |
| 1401 | const sourceRanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1402 | while ((match = this._searchRegex.exec(text)) && match[0]) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1403 | sourceRanges.push(new TextUtils.TextRange.SourceRange(match.index, match[0].length)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1404 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1405 | |
| 1406 | if (sourceRanges.length) { |
| 1407 | this._searchHighlightNodes = |
Sigurd Schneider | e8e75cf | 2020-10-13 08:17:52 | [diff] [blame] | 1408 | UI.UIUtils.highlightSearchResults(this.contentElement(), sourceRanges, this._searchHighlightNodeChanges); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1409 | } |
| 1410 | } |
| 1411 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1412 | searchRegex(): RegExp|null { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1413 | return this._searchRegex; |
| 1414 | } |
| 1415 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1416 | searchCount(): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1417 | return this._searchHighlightNodes.length; |
| 1418 | } |
| 1419 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1420 | searchHighlightNode(index: number): Element { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1421 | return this._searchHighlightNodes[index]; |
| 1422 | } |
| 1423 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1424 | _tryFormatAsError(string: string): HTMLElement|null { |
| 1425 | function startsWith(prefix: string): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1426 | return string.startsWith(prefix); |
| 1427 | } |
| 1428 | |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1429 | const runtimeModel = this._message.runtimeModel(); |
Sigurd Schneider | 8d0fe54 | 2021-03-17 12:28:29 | [diff] [blame^] | 1430 | // TODO: Consider removing these in favor of a simpler regex. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1431 | const errorPrefixes = |
| 1432 | ['EvalError', 'ReferenceError', 'SyntaxError', 'TypeError', 'RangeError', 'Error', 'URIError']; |
Sigurd Schneider | 8d0fe54 | 2021-03-17 12:28:29 | [diff] [blame^] | 1433 | if (!runtimeModel || !errorPrefixes.some(startsWith) && !/^[\w.]+Error\b/.test(string)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1434 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1435 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1436 | const debuggerModel = runtimeModel.debuggerModel(); |
| 1437 | const baseURL = runtimeModel.target().inspectedURL(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1438 | |
| 1439 | const lines = string.split('\n'); |
| 1440 | const links = []; |
| 1441 | let position = 0; |
| 1442 | for (let i = 0; i < lines.length; ++i) { |
| 1443 | position += i > 0 ? lines[i - 1].length + 1 : 0; |
| 1444 | const isCallFrameLine = /^\s*at\s/.test(lines[i]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1445 | if (!isCallFrameLine && links.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1446 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1447 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1448 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1449 | if (!isCallFrameLine) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1450 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1451 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1452 | |
| 1453 | let openBracketIndex = -1; |
| 1454 | let closeBracketIndex = -1; |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1455 | const inBracketsWithLineAndColumn = /\([^\)\(]+:\d+:\d+\)/g; |
| 1456 | const inBrackets = /\([^\)\(]+\)/g; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1457 | let lastMatch: RegExpExecArray|null = null; |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1458 | let currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1459 | while ((currentMatch = inBracketsWithLineAndColumn.exec(lines[i]))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1460 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1461 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1462 | if (!lastMatch) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1463 | while ((currentMatch = inBrackets.exec(lines[i]))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1464 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1465 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1466 | } |
| 1467 | if (lastMatch) { |
| 1468 | openBracketIndex = lastMatch.index; |
| 1469 | closeBracketIndex = lastMatch.index + lastMatch[0].length - 1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1470 | } |
| 1471 | const hasOpenBracket = openBracketIndex !== -1; |
| 1472 | const left = hasOpenBracket ? openBracketIndex + 1 : lines[i].indexOf('at') + 3; |
| 1473 | const right = hasOpenBracket ? closeBracketIndex : lines[i].length; |
| 1474 | const linkCandidate = lines[i].substring(left, right); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1475 | const splitResult = Common.ParsedURL.ParsedURL.splitLineAndColumn(linkCandidate); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1476 | if (!splitResult) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1477 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1478 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1479 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1480 | if (splitResult.url === '<anonymous>') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1481 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1482 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1483 | let url = parseOrScriptMatch(splitResult.url); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1484 | if (!url && Common.ParsedURL.ParsedURL.isRelativeURL(splitResult.url)) { |
| 1485 | url = parseOrScriptMatch(Common.ParsedURL.ParsedURL.completeURL(baseURL, splitResult.url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1486 | } |
| 1487 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1488 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1489 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1490 | |
| 1491 | links.push({ |
| 1492 | url: url, |
| 1493 | positionLeft: position + left, |
| 1494 | positionRight: position + right, |
| 1495 | lineNumber: splitResult.lineNumber, |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1496 | columnNumber: splitResult.columnNumber, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1497 | }); |
| 1498 | } |
| 1499 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1500 | if (!links.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1501 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1502 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1503 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1504 | const formattedResult = document.createElement('span'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1505 | let start = 0; |
| 1506 | for (let i = 0; i < links.length; ++i) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1507 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start, links[i].positionLeft))); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1508 | const scriptLocationLink = this._linkifier.linkifyScriptLocation( |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1509 | debuggerModel.target(), null, links[i].url, links[i].lineNumber, |
| 1510 | {columnNumber: links[i].columnNumber, className: undefined, tabStop: undefined}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1511 | scriptLocationLink.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1512 | this._selectableChildren.push({element: scriptLocationLink, forceSelect: (): void => scriptLocationLink.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1513 | formattedResult.appendChild(scriptLocationLink); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1514 | start = links[i].positionRight; |
| 1515 | } |
| 1516 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1517 | if (start !== string.length) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1518 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start))); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1519 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1520 | |
| 1521 | return formattedResult; |
| 1522 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1523 | function parseOrScriptMatch(url: string|null): string|null { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1524 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1525 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1526 | } |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1527 | const parsedURL = Common.ParsedURL.ParsedURL.fromString(url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1528 | if (parsedURL) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1529 | return parsedURL.url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1530 | } |
| 1531 | if (debuggerModel.scriptsForSourceURL(url).length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1532 | return url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1533 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1534 | return null; |
| 1535 | } |
| 1536 | } |
| 1537 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1538 | _linkifyWithCustomLinkifier( |
| 1539 | string: string, linkifier: (arg0: string, arg1: string, arg2?: number, arg3?: number) => Node): DocumentFragment { |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1540 | if (string.length > getMaxTokenizableStringLength()) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1541 | const propertyValue = new ObjectUI.ObjectPropertiesSection.ExpandableTextPropertyValue( |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1542 | document.createElement('span'), string, getLongStringVisibleLength()); |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1543 | const fragment = document.createDocumentFragment(); |
Connor Moody | 1a5c0d3 | 2019-12-19 07:23:36 | [diff] [blame] | 1544 | fragment.appendChild(propertyValue.element); |
| 1545 | return fragment; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1546 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1547 | const container = document.createDocumentFragment(); |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 1548 | const tokens = ConsoleViewMessage._tokenizeMessageText(string); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1549 | for (const token of tokens) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1550 | if (!token.text) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1551 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1552 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1553 | switch (token.type) { |
| 1554 | case 'url': { |
| 1555 | const realURL = (token.text.startsWith('www.') ? 'http://' + token.text : token.text); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1556 | const splitResult = Common.ParsedURL.ParsedURL.splitLineAndColumn(realURL); |
Kim-Anh Tran | 9e49a45 | 2020-02-17 09:46:10 | [diff] [blame] | 1557 | const sourceURL = Common.ParsedURL.ParsedURL.removeWasmFunctionInfoFromURL(splitResult.url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1558 | let linkNode; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1559 | if (splitResult) { |
Kim-Anh Tran | 9e49a45 | 2020-02-17 09:46:10 | [diff] [blame] | 1560 | linkNode = linkifier(token.text, sourceURL, splitResult.lineNumber, splitResult.columnNumber); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1561 | } else { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1562 | linkNode = linkifier(token.text, ''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1563 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1564 | container.appendChild(linkNode); |
| 1565 | break; |
| 1566 | } |
| 1567 | default: |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1568 | container.appendChild(document.createTextNode(token.text)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1569 | break; |
| 1570 | } |
| 1571 | } |
| 1572 | return container; |
| 1573 | } |
| 1574 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1575 | _linkifyStringAsFragment(string: string): DocumentFragment { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1576 | return this._linkifyWithCustomLinkifier(string, (text, url, lineNumber, columnNumber) => { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1577 | const options = {text, lineNumber, columnNumber}; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1578 | const linkElement = |
| 1579 | Components.Linkifier.Linkifier.linkifyURL(url, (options as Components.Linkifier.LinkifyURLOptions)); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1580 | linkElement.tabIndex = -1; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1581 | this._selectableChildren.push({element: linkElement, forceSelect: (): void => linkElement.focus()}); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1582 | return linkElement; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1583 | }); |
| 1584 | } |
| 1585 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1586 | static _tokenizeMessageText(string: string): { |
| 1587 | type?: string, text: string, |
| 1588 | }[] { |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1589 | const {tokenizerRegexes, tokenizerTypes} = getOrCreateTokenizers(); |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1590 | if (string.length > getMaxTokenizableStringLength()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1591 | return [{text: string, type: undefined}]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1592 | } |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1593 | const results = TextUtils.TextUtils.Utils.splitStringByRegexes(string, tokenizerRegexes); |
| 1594 | return results.map(result => ({text: result.value, type: tokenizerTypes[result.regexIndex]})); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1595 | } |
| 1596 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1597 | groupKey(): string { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1598 | if (!this._groupKey) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1599 | this._groupKey = this._message.groupCategoryKey() + ':' + this.groupTitle(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1600 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1601 | return this._groupKey; |
| 1602 | } |
| 1603 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1604 | groupTitle(): string { |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 1605 | const tokens = ConsoleViewMessage._tokenizeMessageText(this._message.messageText); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1606 | const result = tokens.reduce((acc, token) => { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1607 | let text: Common.UIString.LocalizedString|string = token.text; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1608 | if (token.type === 'url') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1609 | text = i18nString(UIStrings.url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1610 | } else if (token.type === 'time') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1611 | text = i18nString(UIStrings.tookNms); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1612 | } else if (token.type === 'event') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1613 | text = i18nString(UIStrings.someEvent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1614 | } else if (token.type === 'milestone') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1615 | text = i18nString(UIStrings.Mxx); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1616 | } else if (token.type === 'autofill') { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1617 | text = i18nString(UIStrings.attribute); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1618 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1619 | return acc + text; |
| 1620 | }, ''); |
| 1621 | return result.replace(/[%]o/g, ''); |
| 1622 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1623 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1624 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1625 | let tokenizerRegexes: RegExp[]|null = null; |
| 1626 | let tokenizerTypes: string[]|null = null; |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1627 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1628 | function getOrCreateTokenizers(): { |
| 1629 | tokenizerRegexes: Array<RegExp>, |
| 1630 | tokenizerTypes: Array<string>, |
| 1631 | } { |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1632 | if (!tokenizerRegexes || !tokenizerTypes) { |
| 1633 | const controlCodes = '\\u0000-\\u0020\\u007f-\\u009f'; |
| 1634 | const linkStringRegex = new RegExp( |
| 1635 | '(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s' + controlCodes + '"]{2,}[^\\s' + controlCodes + |
| 1636 | '"\')}\\],:;.!?]', |
| 1637 | 'u'); |
| 1638 | const pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; |
| 1639 | const timeRegex = /took [\d]+ms/; |
| 1640 | const eventRegex = /'\w+' event/; |
| 1641 | const milestoneRegex = /\sM[6-7]\d/; |
| 1642 | const autofillRegex = /\(suggested: \"[\w-]+\"\)/; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1643 | const handlers = new Map<RegExp, string>(); |
Sigurd Schneider | 30ac3dd | 2020-10-13 09:06:39 | [diff] [blame] | 1644 | handlers.set(linkStringRegex, 'url'); |
| 1645 | handlers.set(pathLineRegex, 'url'); |
| 1646 | handlers.set(timeRegex, 'time'); |
| 1647 | handlers.set(eventRegex, 'event'); |
| 1648 | handlers.set(milestoneRegex, 'milestone'); |
| 1649 | handlers.set(autofillRegex, 'autofill'); |
| 1650 | tokenizerRegexes = Array.from(handlers.keys()); |
| 1651 | tokenizerTypes = Array.from(handlers.values()); |
| 1652 | return {tokenizerRegexes, tokenizerTypes}; |
| 1653 | } |
| 1654 | return {tokenizerRegexes, tokenizerTypes}; |
| 1655 | } |
| 1656 | |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1657 | export class ConsoleGroupViewMessage extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1658 | _collapsed: boolean; |
| 1659 | _expandGroupIcon: UI.Icon.Icon|null; |
| 1660 | _onToggle: () => void; |
| 1661 | |
| 1662 | constructor( |
| 1663 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1664 | onToggle: () => void, onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1665 | console.assert(consoleMessage.isGroupStartMessage()); |
Tim van der Lippe | b45d9a0 | 2019-11-05 17:24:41 | [diff] [blame] | 1666 | super(consoleMessage, linkifier, nestingLevel, onResize); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1667 | this._collapsed = consoleMessage.type === SDK.ConsoleModel.MessageType.StartGroupCollapsed; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1668 | this._expandGroupIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1669 | this._onToggle = onToggle; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1670 | } |
| 1671 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1672 | _setCollapsed(collapsed: boolean): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1673 | this._collapsed = collapsed; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1674 | if (this._expandGroupIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1675 | this._expandGroupIcon.setIconType(this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1676 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1677 | this._onToggle.call(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1678 | } |
| 1679 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1680 | collapsed(): boolean { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1681 | return this._collapsed; |
| 1682 | } |
| 1683 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1684 | maybeHandleOnKeyDown(event: KeyboardEvent): boolean { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1685 | const focusedChildIndex = this._focusedChildIndex(); |
| 1686 | if (focusedChildIndex === -1) { |
| 1687 | if ((event.key === 'ArrowLeft' && !this._collapsed) || (event.key === 'ArrowRight' && this._collapsed)) { |
| 1688 | this._setCollapsed(!this._collapsed); |
| 1689 | return true; |
| 1690 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1691 | } |
| 1692 | return super.maybeHandleOnKeyDown(event); |
| 1693 | } |
| 1694 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1695 | toMessageElement(): HTMLElement { |
| 1696 | let element: HTMLElement|null = this._element || null; |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1697 | if (!element) { |
| 1698 | element = super.toMessageElement(); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1699 | const iconType = this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 1700 | this._expandGroupIcon = UI.Icon.Icon.create(iconType, 'expand-group-icon'); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 1701 | // Intercept focus to avoid highlight on click. |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1702 | this.contentElement().tabIndex = -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1703 | if (this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1704 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1705 | } else { |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1706 | element.insertBefore(this._expandGroupIcon, this._contentElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1707 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1708 | element.addEventListener('click', () => this._setCollapsed(!this._collapsed)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1709 | } |
Sigurd Schneider | 45f32c3 | 2020-10-13 13:32:05 | [diff] [blame] | 1710 | return element; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1711 | } |
| 1712 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1713 | _showRepeatCountElement(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1714 | super._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1715 | if (this._repeatCountElement && this._expandGroupIcon) { |
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 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1718 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 1719 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1720 | |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1721 | export class ConsoleCommand extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1722 | _formattedCommand: HTMLElement|null; |
| 1723 | |
| 1724 | constructor( |
| 1725 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1726 | onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1727 | super(consoleMessage, linkifier, nestingLevel, onResize); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1728 | this._formattedCommand = null; |
| 1729 | } |
| 1730 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1731 | contentElement(): HTMLElement { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1732 | const contentElement = this.getContentElement(); |
| 1733 | if (contentElement) { |
| 1734 | return contentElement; |
| 1735 | } |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1736 | const newContentElement = (document.createElement('div') as HTMLElement); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1737 | this.setContentElement(newContentElement); |
| 1738 | newContentElement.classList.add('console-user-command'); |
| 1739 | const icon = UI.Icon.Icon.create('smallicon-user-command', 'command-result-icon'); |
| 1740 | newContentElement.appendChild(icon); |
| 1741 | |
| 1742 | elementToMessage.set(newContentElement, this); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1743 | this._formattedCommand = (document.createElement('span') as HTMLElement); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1744 | this._formattedCommand.classList.add('source-code'); |
| 1745 | this._formattedCommand.textContent = Platform.StringUtilities.replaceControlCharacters(this.text); |
| 1746 | newContentElement.appendChild(this._formattedCommand); |
| 1747 | |
| 1748 | if (this._formattedCommand.textContent.length < MaxLengthToIgnoreHighlighter) { |
Andres Olivares | f59e6de | 2021-02-18 13:10:25 | [diff] [blame] | 1749 | const javascriptSyntaxHighlighter = new TextEditor.SyntaxHighlighter.SyntaxHighlighter('text/javascript', true); |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1750 | javascriptSyntaxHighlighter.syntaxHighlightNode(this._formattedCommand).then(this._updateSearch.bind(this)); |
| 1751 | } else { |
| 1752 | this._updateSearch(); |
| 1753 | } |
| 1754 | |
| 1755 | this.updateTimestamp(); |
| 1756 | return newContentElement; |
| 1757 | } |
| 1758 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1759 | _updateSearch(): void { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1760 | this.setSearchRegex(this.searchRegex()); |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | export class ConsoleCommandResult extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1765 | contentElement(): HTMLElement { |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1766 | const element = super.contentElement(); |
| 1767 | if (!element.classList.contains('console-user-command-result')) { |
| 1768 | element.classList.add('console-user-command-result'); |
| 1769 | if (this.consoleMessage().level === SDK.ConsoleModel.MessageLevel.Info) { |
| 1770 | const icon = UI.Icon.Icon.create('smallicon-command-result', 'command-result-icon'); |
| 1771 | element.insertBefore(icon, element.firstChild); |
| 1772 | } |
| 1773 | } |
| 1774 | return element; |
| 1775 | } |
| 1776 | } |
| 1777 | |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1778 | export class ConsoleTableMessageView extends ConsoleViewMessage { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1779 | _dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<unknown>|null; |
| 1780 | |
| 1781 | constructor( |
| 1782 | consoleMessage: SDK.ConsoleModel.ConsoleMessage, linkifier: Components.Linkifier.Linkifier, nestingLevel: number, |
| 1783 | onResize: (arg0: Common.EventTarget.EventTargetEvent) => void) { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1784 | super(consoleMessage, linkifier, nestingLevel, onResize); |
| 1785 | console.assert(consoleMessage.type === SDK.ConsoleModel.MessageType.Table); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1786 | this._dataGrid = null; |
| 1787 | } |
| 1788 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1789 | wasShown(): void { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1790 | if (this._dataGrid) { |
| 1791 | this._dataGrid.updateWidths(); |
| 1792 | } |
| 1793 | super.wasShown(); |
| 1794 | } |
| 1795 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1796 | onResize(): void { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1797 | if (!this.isVisible()) { |
| 1798 | return; |
| 1799 | } |
| 1800 | if (this._dataGrid) { |
| 1801 | this._dataGrid.onResize(); |
| 1802 | } |
| 1803 | } |
| 1804 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1805 | contentElement(): HTMLElement { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1806 | const contentElement = this.getContentElement(); |
| 1807 | if (contentElement) { |
| 1808 | return contentElement; |
| 1809 | } |
| 1810 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1811 | const newContentElement = (document.createElement('div') as HTMLElement); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1812 | newContentElement.classList.add('console-message'); |
| 1813 | if (this._messageLevelIcon) { |
| 1814 | newContentElement.appendChild(this._messageLevelIcon); |
| 1815 | } |
| 1816 | this.setContentElement(newContentElement); |
| 1817 | |
| 1818 | newContentElement.appendChild(this._buildTableMessage()); |
| 1819 | this.updateTimestamp(); |
| 1820 | return newContentElement; |
| 1821 | } |
| 1822 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1823 | _buildTableMessage(): HTMLElement { |
| 1824 | const formattedMessage = (document.createElement('span') as HTMLElement); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1825 | formattedMessage.classList.add('source-code'); |
| 1826 | this._anchorElement = this._buildMessageAnchor(); |
| 1827 | if (this._anchorElement) { |
| 1828 | formattedMessage.appendChild(this._anchorElement); |
| 1829 | } |
| 1830 | |
| 1831 | const table = this._message.parameters && this._message.parameters.length ? this._message.parameters[0] : null; |
| 1832 | if (!table) { |
| 1833 | return this._buildMessage(); |
| 1834 | } |
| 1835 | const actualTable = parameterToRemoteObject(this._message.runtimeModel())(table); |
| 1836 | if (!actualTable || !actualTable.preview) { |
| 1837 | return this._buildMessage(); |
| 1838 | } |
| 1839 | |
| 1840 | const rawValueColumnSymbol = Symbol('rawValueColumn'); |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1841 | const columnNames: (string|symbol)[] = []; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1842 | const preview = actualTable.preview; |
| 1843 | const rows = []; |
| 1844 | for (let i = 0; i < preview.properties.length; ++i) { |
| 1845 | const rowProperty = preview.properties[i]; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1846 | let rowSubProperties: Protocol.Runtime.PropertyPreview[]; |
Sigurd Schneider | b393a43 | 2020-11-06 12:08:21 | [diff] [blame] | 1847 | if (rowProperty.valuePreview && rowProperty.valuePreview.properties.length) { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1848 | rowSubProperties = rowProperty.valuePreview.properties; |
| 1849 | } else if (rowProperty.value) { |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1850 | rowSubProperties = |
| 1851 | [{name: rawValueColumnSymbol as unknown as string, type: rowProperty.type, value: rowProperty.value}]; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1852 | } else { |
| 1853 | continue; |
| 1854 | } |
| 1855 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1856 | const rowValue = new Map<string|symbol, HTMLElement>(); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1857 | const maxColumnsToRender = 20; |
| 1858 | for (let j = 0; j < rowSubProperties.length; ++j) { |
| 1859 | const cellProperty = rowSubProperties[j]; |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1860 | let columnRendered: true|boolean = columnNames.indexOf(cellProperty.name) !== -1; |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1861 | if (!columnRendered) { |
| 1862 | if (columnNames.length === maxColumnsToRender) { |
| 1863 | continue; |
| 1864 | } |
| 1865 | columnRendered = true; |
| 1866 | columnNames.push(cellProperty.name); |
| 1867 | } |
| 1868 | |
| 1869 | if (columnRendered) { |
| 1870 | const cellElement = |
| 1871 | this._renderPropertyPreviewOrAccessor(actualTable, cellProperty, [rowProperty, cellProperty]); |
| 1872 | cellElement.classList.add('console-message-nowrap-below'); |
| 1873 | rowValue.set(cellProperty.name, cellElement); |
| 1874 | } |
| 1875 | } |
| 1876 | rows.push({rowName: rowProperty.name, rowValue}); |
| 1877 | } |
| 1878 | |
| 1879 | const flatValues = []; |
| 1880 | for (const {rowName, rowValue} of rows) { |
| 1881 | flatValues.push(rowName); |
| 1882 | for (let j = 0; j < columnNames.length; ++j) { |
| 1883 | flatValues.push(rowValue.get(columnNames[j])); |
| 1884 | } |
| 1885 | } |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1886 | columnNames.unshift(i18nString(UIStrings.index)); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1887 | const columnDisplayNames = |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1888 | columnNames.map(name => name === rawValueColumnSymbol ? i18nString(UIStrings.value) : name.toString()); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1889 | |
| 1890 | if (flatValues.length) { |
Christy Chen | 9c6d898 | 2021-02-08 02:28:31 | [diff] [blame] | 1891 | this._dataGrid = DataGrid.SortableDataGrid.SortableDataGrid.create( |
| 1892 | columnDisplayNames, flatValues, i18nString(UIStrings.console)); |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1893 | if (this._dataGrid) { |
| 1894 | this._dataGrid.setStriped(true); |
| 1895 | this._dataGrid.setFocusable(false); |
| 1896 | |
| 1897 | const formattedResult = document.createElement('span'); |
| 1898 | formattedResult.classList.add('console-message-text'); |
| 1899 | const tableElement = formattedResult.createChild('div', 'console-message-formatted-table'); |
| 1900 | const dataGridContainer = tableElement.createChild('span'); |
| 1901 | tableElement.appendChild(this._formatParameter(actualTable, true, false)); |
| 1902 | dataGridContainer.appendChild(this._dataGrid.element); |
| 1903 | formattedMessage.appendChild(formattedResult); |
| 1904 | this._dataGrid.renderInline(); |
| 1905 | } |
| 1906 | } |
| 1907 | return formattedMessage; |
| 1908 | } |
| 1909 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1910 | approximateFastHeight(): number { |
Sigurd Schneider | 8bfb421 | 2020-10-27 10:27:37 | [diff] [blame] | 1911 | const table = this._message.parameters && this._message.parameters[0]; |
| 1912 | if (table && typeof table !== 'string' && table.preview) { |
| 1913 | return defaultConsoleRowHeight * table.preview.properties.length; |
| 1914 | } |
| 1915 | return defaultConsoleRowHeight; |
| 1916 | } |
| 1917 | } |
| 1918 | |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1919 | /** |
| 1920 | * The maximum length before strings are considered too long for syntax highlighting. |
| 1921 | * @const |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1922 | */ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1923 | const MaxLengthToIgnoreHighlighter: number = 10000; |
Sigurd Schneider | ca7b4ff | 2020-10-14 07:45:47 | [diff] [blame] | 1924 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1925 | /** |
| 1926 | * @const |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1927 | */ |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1928 | export const MaxLengthForLinks: number = 40; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1929 | |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 1930 | let maxTokenizableStringLength = 10000; |
| 1931 | let longStringVisibleLength = 5000; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1932 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1933 | export const getMaxTokenizableStringLength = (): number => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 1934 | return maxTokenizableStringLength; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1935 | }; |
| 1936 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1937 | export const setMaxTokenizableStringLength = (length: number): void => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 1938 | maxTokenizableStringLength = length; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1939 | }; |
| 1940 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1941 | export const getLongStringVisibleLength = (): number => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 1942 | return longStringVisibleLength; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1943 | }; |
| 1944 | |
Jan Scheffler | 19cd7ec | 2021-02-12 14:16:30 | [diff] [blame] | 1945 | export const setLongStringVisibleLength = (length: number): void => { |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 1946 | longStringVisibleLength = length; |
Sigurd Schneider | 8f4ac86 | 2020-10-13 13:30:11 | [diff] [blame] | 1947 | }; |