chrome-devtools-frontend 1.0.953446 → 1.0.954271

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/config/gni/devtools_grd_files.gni +4 -0
  2. package/front_end/core/common/Settings.ts +10 -0
  3. package/front_end/core/i18n/i18nImpl.ts +8 -30
  4. package/front_end/core/i18n/locales/en-US.json +7 -16
  5. package/front_end/core/i18n/locales/en-XL.json +7 -16
  6. package/front_end/core/platform/number-utilities.ts +5 -7
  7. package/front_end/core/platform/string-utilities.ts +45 -205
  8. package/front_end/core/sdk/EmulationModel.ts +18 -19
  9. package/front_end/core/sdk/ResourceTreeModel.ts +12 -2
  10. package/front_end/core/sdk/sdk-meta.ts +2 -39
  11. package/front_end/entrypoints/inspector_main/RenderingOptions.ts +13 -9
  12. package/front_end/generated/InspectorBackendCommands.js +3 -1
  13. package/front_end/generated/protocol.d.ts +19 -0
  14. package/front_end/models/extensions/ExtensionServer.ts +2 -3
  15. package/front_end/panels/application/components/BackForwardCacheView.ts +6 -4
  16. package/front_end/panels/application/components/EndpointsGrid.ts +1 -1
  17. package/front_end/panels/application/storageView.css +1 -1
  18. package/front_end/panels/console/ConsoleFormat.ts +155 -0
  19. package/front_end/panels/console/ConsoleViewMessage.ts +54 -155
  20. package/front_end/panels/console/console.ts +3 -0
  21. package/front_end/panels/elements/components/AdornerSettingsPane.ts +2 -1
  22. package/front_end/panels/elements/components/LayoutPane.ts +2 -0
  23. package/front_end/panels/elements/elementStatePaneWidget.css +1 -1
  24. package/front_end/panels/elements/layoutPane.css +0 -4
  25. package/front_end/panels/emulation/components/DeviceSizeInputElement.ts +5 -1
  26. package/front_end/panels/network/NetworkDataGridNode.ts +0 -2
  27. package/front_end/panels/network/components/WebBundleInfoView.ts +1 -1
  28. package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +2 -1
  29. package/front_end/panels/web_audio/webAudio.css +1 -1
  30. package/front_end/third_party/puppeteer/package/README.md +11 -11
  31. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/AriaQueryHandler.js +2 -2
  32. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/AriaQueryHandler.js.map +1 -1
  33. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.d.ts +2 -0
  34. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.d.ts.map +1 -1
  35. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.js +20 -11
  36. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/DOMWorld.js.map +1 -1
  37. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.d.ts.map +1 -1
  38. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.js +13 -3
  39. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/JSHandle.js.map +1 -1
  40. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/AriaQueryHandler.js +2 -2
  41. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/AriaQueryHandler.js.map +1 -1
  42. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.d.ts +2 -0
  43. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.d.ts.map +1 -1
  44. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.js +20 -11
  45. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/DOMWorld.js.map +1 -1
  46. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.d.ts.map +1 -1
  47. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.js +13 -3
  48. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/JSHandle.js.map +1 -1
  49. package/front_end/third_party/puppeteer/package/lib/types.d.ts +2 -0
  50. package/front_end/third_party/puppeteer/package/package.json +1 -1
  51. package/front_end/ui/components/input/checkbox.css +11 -0
  52. package/front_end/ui/components/input/input.ts +3 -3
  53. package/front_end/ui/components/linear_memory_inspector/ValueInterpreterSettings.ts +2 -1
  54. package/front_end/ui/components/markdown_view/MarkdownView.ts +1 -1
  55. package/front_end/ui/components/panel_feedback/PreviewToggle.ts +2 -1
  56. package/front_end/ui/components/settings/SettingCheckbox.ts +5 -3
  57. package/front_end/ui/components/settings/settingCheckbox.css +0 -5
  58. package/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts +10 -3
  59. package/front_end/ui/legacy/SettingsUI.ts +1 -0
  60. package/front_end/ui/legacy/UIUtils.ts +0 -12
  61. package/front_end/ui/legacy/themeColors.css +3 -2
  62. package/front_end/ui/legacy/treeoutline.css +1 -1
  63. package/package.json +1 -1
  64. package/scripts/eslint_rules/lib/lit_html_host_this.js +1 -10
  65. package/scripts/eslint_rules/lib/utils.js +20 -1
  66. package/scripts/eslint_rules/tests/utils_test.js +30 -0
@@ -314,26 +314,6 @@ const UIStrings = {
314
314
  * emulates that the webpage is in auto dark mode.
315
315
  */
316
316
  emulateAutoDarkMode: 'Emulate auto dark mode',
317
- /**
318
- * @description Title of a setting for enabling auto dark mode.
319
- */
320
- enableEmulateAutoDarkMode: 'Enable auto dark mode',
321
- /**
322
- * @description Text to emulate enabled auto dark mode.
323
- */
324
- enabledDarkMode: 'Enable',
325
- /**
326
- * @description Title of a setting for disabling auto dark mode.
327
- */
328
- disableEmulateAutoDarkMode: 'Disable auto dark mode',
329
- /**
330
- * @description Text to emulate disabled auto dark mode.
331
- */
332
- disabledDarkMode: 'Disable',
333
- /**
334
- * @description Title of a setting for disabling dark mode emulation.
335
- */
336
- doNotEmulateDarkMode: 'Do not emulate auto dark mode',
337
317
  };
338
318
  const str_ = i18n.i18n.registerUIStrings('core/sdk/sdk-meta.ts', UIStrings);
339
319
  const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
@@ -1049,24 +1029,7 @@ Common.Settings.registerSettingExtension({
1049
1029
  category: Common.Settings.SettingCategory.RENDERING,
1050
1030
  title: i18nLazyString(UIStrings.emulateAutoDarkMode),
1051
1031
  settingName: 'emulateAutoDarkMode',
1052
- settingType: Common.Settings.SettingType.ENUM,
1032
+ settingType: Common.Settings.SettingType.BOOLEAN,
1053
1033
  storageType: Common.Settings.SettingStorageType.Session,
1054
- defaultValue: 'default',
1055
- options: [
1056
- {
1057
- title: i18nLazyString(UIStrings.doNotEmulateDarkMode),
1058
- text: i18nLazyString(UIStrings.noEmulation),
1059
- value: 'default',
1060
- },
1061
- {
1062
- title: i18nLazyString(UIStrings.enableEmulateAutoDarkMode),
1063
- text: i18nLazyString(UIStrings.enabledDarkMode),
1064
- value: 'enabled',
1065
- },
1066
- {
1067
- title: i18nLazyString(UIStrings.disableEmulateAutoDarkMode),
1068
- text: i18nLazyString(UIStrings.disabledDarkMode),
1069
- value: 'disabled',
1070
- },
1071
- ],
1034
+ defaultValue: false,
1072
1035
  });
@@ -124,9 +124,13 @@ const UIStrings = {
124
124
  */
125
125
  emulatesAFocusedPage: 'Emulates a focused page.',
126
126
  /**
127
- * @description Explanation text for the 'Emulate a focused page' setting in the Rendering tool.
127
+ * @description The name of a checkbox setting in the Rendering tool. This setting enables auto dark mode emulation.
128
+ */
129
+ emulateAutoDarkMode: 'Enable automatic dark mode',
130
+ /**
131
+ * @description Explanation text for the 'Emulate automatic dark mode' setting in the Rendering tool.
128
132
  */
129
- emulatesAutoDarkMode: 'Enables automatic dark mode for the inspected page.',
133
+ emulatesAutoDarkMode: 'Enables automatic dark mode and sets `prefers-color-scheme` to `dark`.',
130
134
  /**
131
135
  * @description Explanation text for the 'Emulate CSS media type' setting in the Rendering tool.
132
136
  * This setting overrides the CSS media type on the page:
@@ -245,14 +249,18 @@ export class RenderingOptionsView extends UI.Widget.VBox {
245
249
  this.#appendCheckbox(
246
250
  i18nString(UIStrings.emulateAFocusedPage), i18nString(UIStrings.emulatesAFocusedPage),
247
251
  Common.Settings.Settings.instance().moduleSetting('emulatePageFocus'));
252
+ this.#appendCheckbox(
253
+ i18nString(UIStrings.emulateAutoDarkMode), i18nString(UIStrings.emulatesAutoDarkMode),
254
+ Common.Settings.Settings.instance().moduleSetting('emulateAutoDarkMode'));
255
+
248
256
  this.contentElement.createChild('div').classList.add('panel-section-separator');
249
257
 
250
- this.#appendSelect(
251
- i18nString(UIStrings.forcesMediaTypeForTestingPrint),
252
- Common.Settings.Settings.instance().moduleSetting('emulatedCSSMedia'));
253
258
  this.#appendSelect(
254
259
  i18nString(UIStrings.forcesCssPreferscolorschemeMedia),
255
260
  Common.Settings.Settings.instance().moduleSetting('emulatedCSSMediaFeaturePrefersColorScheme'));
261
+ this.#appendSelect(
262
+ i18nString(UIStrings.forcesMediaTypeForTestingPrint),
263
+ Common.Settings.Settings.instance().moduleSetting('emulatedCSSMedia'));
256
264
  this.#appendSelect(
257
265
  i18nString(UIStrings.forcesCssForcedColors),
258
266
  Common.Settings.Settings.instance().moduleSetting('emulatedCSSMediaFeatureForcedColors'));
@@ -279,10 +287,6 @@ export class RenderingOptionsView extends UI.Widget.VBox {
279
287
  Common.Settings.Settings.instance().moduleSetting('emulatedVisionDeficiency'));
280
288
 
281
289
  this.contentElement.createChild('div').classList.add('panel-section-separator');
282
- this.#appendSelect(
283
- i18nString(UIStrings.emulatesAutoDarkMode),
284
- Common.Settings.Settings.instance().moduleSetting('emulateAutoDarkMode'));
285
- this.contentElement.createChild('div').classList.add('panel-section-separator');
286
290
 
287
291
  this.#appendCheckbox(
288
292
  i18nString(UIStrings.disableAvifImageFormat), i18nString(UIStrings.requiresAPageReloadToApplyAnd),
@@ -2262,7 +2262,9 @@ export function registerCommands(inspectorBackend) {
2262
2262
  inspectorBackend.registerEvent(
2263
2263
  'Page.javascriptDialogOpening', ['url', 'message', 'type', 'hasBrowserHandler', 'defaultPrompt']);
2264
2264
  inspectorBackend.registerEvent('Page.lifecycleEvent', ['frameId', 'loaderId', 'name', 'timestamp']);
2265
- inspectorBackend.registerEvent('Page.backForwardCacheNotUsed', ['loaderId', 'frameId', 'notRestoredExplanations']);
2265
+ inspectorBackend.registerEvent(
2266
+ 'Page.backForwardCacheNotUsed',
2267
+ ['loaderId', 'frameId', 'notRestoredExplanations', 'notRestoredExplanationsTree']);
2266
2268
  inspectorBackend.registerEvent('Page.loadEventFired', ['timestamp']);
2267
2269
  inspectorBackend.registerEvent('Page.navigatedWithinDocument', ['frameId', 'url']);
2268
2270
  inspectorBackend.registerEvent('Page.screencastFrame', ['data', 'metadata', 'sessionId']);
@@ -10719,6 +10719,21 @@ declare namespace Protocol {
10719
10719
  reason: BackForwardCacheNotRestoredReason;
10720
10720
  }
10721
10721
 
10722
+ export interface BackForwardCacheNotRestoredExplanationTree {
10723
+ /**
10724
+ * URL of each frame
10725
+ */
10726
+ url: string;
10727
+ /**
10728
+ * Not restored reasons of each frame
10729
+ */
10730
+ explanations: BackForwardCacheNotRestoredExplanation[];
10731
+ /**
10732
+ * Array of children frame
10733
+ */
10734
+ children: BackForwardCacheNotRestoredExplanationTree[];
10735
+ }
10736
+
10722
10737
  export interface AddScriptToEvaluateOnLoadRequest {
10723
10738
  scriptSource: string;
10724
10739
  }
@@ -11708,6 +11723,10 @@ declare namespace Protocol {
11708
11723
  * Array of reasons why the page could not be cached. This must not be empty.
11709
11724
  */
11710
11725
  notRestoredExplanations: BackForwardCacheNotRestoredExplanation[];
11726
+ /**
11727
+ * Tree structure of reasons why the page could not be cached for each frame.
11728
+ */
11729
+ notRestoredExplanationsTree?: BackForwardCacheNotRestoredExplanationTree;
11711
11730
  }
11712
11731
 
11713
11732
  export interface LoadEventFiredEvent {
@@ -1145,12 +1145,11 @@ export class ExtensionStatus {
1145
1145
  E_FAILED: (...args: unknown[]) => Record;
1146
1146
 
1147
1147
  constructor() {
1148
- function makeStatus(code: string, description: string): Record {
1149
- const details = Array.prototype.slice.call(arguments, 2);
1148
+ function makeStatus(code: string, description: string, ...details: unknown[]): Record {
1150
1149
  const status: Record = {code, description, details};
1151
1150
  if (code !== 'OK') {
1152
1151
  status.isError = true;
1153
- console.error('Extension server error: ' + Platform.StringUtilities.vsprintf(description, details));
1152
+ console.error('Extension server error: ' + Platform.StringUtilities.sprintf(description, ...details));
1154
1153
  }
1155
1154
  return status;
1156
1155
  }
@@ -238,7 +238,9 @@ export class BackForwardCacheView extends HTMLElement {
238
238
  `;
239
239
  // clang-format on
240
240
  }
241
- const isDisabled = this.#screenStatus === ScreenStatusType.Running;
241
+ const isTestRunning = (this.#screenStatus === ScreenStatusType.Running);
242
+ // Prevent running BFCache test on the DevTools window itself via DevTools on DevTools
243
+ const isTestingForbidden = this.#frame.url.startsWith('devtools://');
242
244
  // clang-format off
243
245
  return LitHtml.html`
244
246
  ${this.#renderBackForwardCacheStatus(this.#frame.backForwardCacheDetails.restoredFromCache)}
@@ -252,11 +254,11 @@ export class BackForwardCacheView extends HTMLElement {
252
254
  </div>
253
255
  <${ReportView.ReportView.ReportSection.litTagName}>
254
256
  <${Buttons.Button.Button.litTagName}
255
- .disabled=${isDisabled}
256
- .spinner=${isDisabled}
257
+ .disabled=${isTestRunning || isTestingForbidden}
258
+ .spinner=${isTestRunning}
257
259
  .variant=${Buttons.Button.Variant.PRIMARY}
258
260
  @click=${this.#navigateAwayAndBack}>
259
- ${isDisabled ? LitHtml.html`
261
+ ${isTestRunning ? LitHtml.html`
260
262
  ${i18nString(UIStrings.runningTest)}`:`
261
263
  ${i18nString(UIStrings.runTest)}
262
264
  `}
@@ -86,7 +86,7 @@ export class EndpointsGrid extends HTMLElement {
86
86
  </div>
87
87
  `}
88
88
  </div>
89
- `, this.#shadow);
89
+ `, this.#shadow, {host: this});
90
90
  // clang-format on
91
91
  }
92
92
 
@@ -30,7 +30,7 @@
30
30
  }
31
31
 
32
32
  .quota-override-notification-editor {
33
- border: solid 1px var(--color-background-highlight);
33
+ border: solid 1px var(--color-details-hairline);
34
34
  display: flex;
35
35
  flex: auto;
36
36
  margin-right: 4px;
@@ -0,0 +1,155 @@
1
+ // Copyright 2021 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
+
5
+ import type * as SDK from '../../core/sdk/sdk.js';
6
+
7
+ // TODO(crbug/1282837): This is too naive and doesn't support
8
+ // most (anticipated) uses of the ANSI color sequences (i.e.
9
+ // setting both foreground and background color).
10
+ const ANSI_COLOR_CODES = new Map([
11
+ // Foreground codes
12
+ [30, 'color:black'],
13
+ [31, 'color:red'],
14
+ [32, 'color:green'],
15
+ [33, 'color:yellow'],
16
+ [34, 'color:blue'],
17
+ [35, 'color:magenta'],
18
+ [36, 'color:cyan'],
19
+ [37, 'color:lightGray'],
20
+ [39, 'color:default'],
21
+ [90, 'color:darkGray'],
22
+ [91, 'color:lightRed'],
23
+ [92, 'color:lightGreen'],
24
+ [93, 'color:lightYellow'],
25
+ [94, 'color:lightBlue'],
26
+ [95, 'color:lightMagenta'],
27
+ [96, 'color:lightCyan'],
28
+ [97, 'color:white'],
29
+ // Background codes
30
+ [40, 'background:black'],
31
+ [41, 'background:red'],
32
+ [42, 'background:green'],
33
+ [43, 'background:yellow'],
34
+ [44, 'background:blue'],
35
+ [45, 'background:magenta'],
36
+ [46, 'background:cyan'],
37
+ [47, 'background:lightGray'],
38
+ [49, 'background:default'],
39
+ [100, 'background:darkGray'],
40
+ [101, 'background:lightRed'],
41
+ [102, 'background:lightGreen'],
42
+ [103, 'background:lightYellow'],
43
+ [104, 'background:lightBlue'],
44
+ [105, 'background:lightMagenta'],
45
+ [106, 'background:lightCyan'],
46
+ [107, 'background:white'],
47
+ ]);
48
+
49
+ export type FormatToken = {
50
+ type: 'generic'|'optimal',
51
+ value: SDK.RemoteObject.RemoteObject,
52
+ }|{
53
+ type: 'string' | 'style',
54
+ value: string,
55
+ };
56
+
57
+ /**
58
+ * This is the front-end part of the Formatter function specified in the
59
+ * Console Standard (https://console.spec.whatwg.org/#formatter). Here we
60
+ * assume that all type conversions have already happened in V8 before and
61
+ * are only concerned with performing the actual substitutions and dealing
62
+ * with generic and optimal object formatting as well as styling.
63
+ *
64
+ * @param fmt the format string.
65
+ * @param args the substitution arguments for `fmt`.
66
+ * @returns a list of `FormatToken`s as well as the unused arguments.
67
+ */
68
+ export const format = (fmt: string, args: SDK.RemoteObject.RemoteObject[]): {
69
+ tokens: FormatToken[],
70
+ args: SDK.RemoteObject.RemoteObject[],
71
+ } => {
72
+ const tokens: FormatToken[] = [];
73
+
74
+ function addStringToken(value: string): void {
75
+ if (!value) {
76
+ return;
77
+ }
78
+ if (tokens.length && tokens[tokens.length - 1].type === 'string') {
79
+ tokens[tokens.length - 1].value += value;
80
+ return;
81
+ }
82
+ tokens.push({type: 'string', value});
83
+ }
84
+
85
+ let argIndex = 0;
86
+ const re = /%([%_Oocsdfi])|\x1B\[(\d+)m/;
87
+ for (let match = re.exec(fmt); match !== null; match = re.exec(fmt)) {
88
+ addStringToken(match.input.substring(0, match.index));
89
+ let substitution: number|string|undefined = undefined;
90
+ const specifier = match[1];
91
+ switch (specifier) {
92
+ case '%':
93
+ addStringToken('%');
94
+ substitution = '';
95
+ break;
96
+ case 's':
97
+ if (argIndex < args.length) {
98
+ const {description} = args[argIndex++];
99
+ substitution = description ?? '';
100
+ }
101
+ break;
102
+ case 'c':
103
+ if (argIndex < args.length) {
104
+ const type = 'style';
105
+ const value = args[argIndex++].description ?? '';
106
+ tokens.push({type, value});
107
+ substitution = '';
108
+ }
109
+ break;
110
+ case 'o':
111
+ case 'O':
112
+ if (argIndex < args.length) {
113
+ const type = specifier === 'O' ? 'generic' : 'optimal';
114
+ const value = args[argIndex++];
115
+ tokens.push({type, value});
116
+ substitution = '';
117
+ }
118
+ break;
119
+ case '_':
120
+ if (argIndex < args.length) {
121
+ argIndex++;
122
+ substitution = '';
123
+ }
124
+ break;
125
+ case 'd':
126
+ case 'f':
127
+ case 'i':
128
+ if (argIndex < args.length) {
129
+ const {value} = args[argIndex++];
130
+ substitution = typeof value !== 'number' ? NaN : value;
131
+ if (specifier !== 'f') {
132
+ substitution = Math.floor(substitution);
133
+ }
134
+ }
135
+ break;
136
+ case undefined: {
137
+ const value = ANSI_COLOR_CODES.get(parseInt(match[2], 10));
138
+ if (value !== undefined) {
139
+ const type = 'style';
140
+ tokens.push({type, value});
141
+ substitution = '';
142
+ }
143
+ break;
144
+ }
145
+ }
146
+ if (substitution === undefined) {
147
+ // If there's no substitution, emit the original specifier / sequence verbatim.
148
+ addStringToken(match[0]);
149
+ substitution = '';
150
+ }
151
+ fmt = substitution + match.input.substring(match.index + match[0].length);
152
+ }
153
+ addStringToken(fmt);
154
+ return {tokens, args: args.slice(argIndex)};
155
+ };
@@ -53,6 +53,7 @@ import * as UI from '../../ui/legacy/legacy.js';
53
53
  import objectValueStyles from '../../ui/legacy/components/object_ui/objectValue.css.js';
54
54
  import type {Chrome} from '../../../extension-api/ExtensionAPI.js'; // eslint-disable-line rulesdir/es_modules_import
55
55
 
56
+ import {format} from './ConsoleFormat.js';
56
57
  import type {ConsoleViewportElement} from './ConsoleViewport.js';
57
58
  import consoleViewStyles from './consoleView.css.js';
58
59
 
@@ -586,9 +587,8 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
586
587
 
587
588
  // Multiple parameters with the first being a format string. Save unused substitutions.
588
589
  if (shouldFormatMessage) {
589
- const result = this.formatWithSubstitutionString(
590
+ parameters = this.formatWithSubstitutionString(
590
591
  (parameters[0].description as string), parameters.slice(1), formattedResult);
591
- parameters = Array.from(result.unusedSubstitutions || []);
592
592
  if (parameters.length) {
593
593
  UI.UIUtils.createTextChild(formattedResult, ' ');
594
594
  }
@@ -866,165 +866,64 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
866
866
  }
867
867
 
868
868
  private formatWithSubstitutionString(
869
- format: string, parameters: SDK.RemoteObject.RemoteObject[], formattedResult: HTMLElement): {
870
- formattedResult: Element,
871
- unusedSubstitutions: ArrayLike<SDK.RemoteObject.RemoteObject>|null,
872
- } {
873
- function parameterFormatter(
874
- this: ConsoleViewMessage, force: boolean, includePreview: boolean,
875
- obj?: string|SDK.RemoteObject.RemoteObject): string|HTMLElement|undefined {
876
- if (obj instanceof SDK.RemoteObject.RemoteObject) {
877
- return this.formatParameter(obj, force, includePreview);
878
- }
879
- return stringFormatter(obj);
880
- }
881
-
882
- function stringFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|undefined {
883
- if (obj === undefined) {
884
- return undefined;
885
- }
886
- if (typeof obj === 'string') {
887
- return obj;
888
- }
889
- return obj.description;
890
- }
891
-
892
- function floatFormatter(obj?: string|SDK.RemoteObject.RemoteObject): number|string|undefined {
893
- if (obj instanceof SDK.RemoteObject.RemoteObject) {
894
- if (typeof obj.value !== 'number') {
895
- return 'NaN';
896
- }
897
- return obj.value;
898
- }
899
- return undefined;
900
- }
901
-
902
- function integerFormatter(obj?: string|SDK.RemoteObject.RemoteObject): string|number|undefined {
903
- if (obj instanceof SDK.RemoteObject.RemoteObject) {
904
- if (obj.type === 'bigint') {
905
- return obj.description;
906
- }
907
- if (typeof obj.value !== 'number') {
908
- return 'NaN';
869
+ formatString: string, parameters: SDK.RemoteObject.RemoteObject[],
870
+ formattedResult: HTMLElement): SDK.RemoteObject.RemoteObject[] {
871
+ const currentStyle = new Map();
872
+ const {tokens, args} = format(formatString, parameters);
873
+ for (const token of tokens) {
874
+ switch (token.type) {
875
+ case 'generic': {
876
+ formattedResult.append(this.formatParameter(token.value, true /* force */, false /* includePreview */));
877
+ break;
909
878
  }
910
- return Math.floor(obj.value);
911
- }
912
- return undefined;
913
- }
914
-
915
- function bypassFormatter(obj?: string|SDK.RemoteObject.RemoteObject): Node|string {
916
- return (obj instanceof Node) ? obj : '';
917
- }
918
-
919
- let currentStyle: Map<string, {value: string, priority: string}>|null = null;
920
- function styleFormatter(obj?: string|SDK.RemoteObject.RemoteObject): void {
921
- currentStyle = new Map();
922
- const buffer = document.createElement('span');
923
- if (obj === undefined) {
924
- return;
925
- }
926
- if (typeof obj === 'string' || !obj.description) {
927
- return;
928
- }
929
- buffer.setAttribute('style', obj.description);
930
- for (const property of buffer.style) {
931
- if (isAllowedProperty(property)) {
932
- const info = {
933
- value: buffer.style.getPropertyValue(property),
934
- priority: buffer.style.getPropertyPriority(property),
935
- };
936
- currentStyle.set(property, info);
879
+ case 'optimal': {
880
+ formattedResult.append(this.formatParameter(token.value, false /* force */, true /* includePreview */));
881
+ break;
937
882
  }
938
- }
939
- }
940
-
941
- function isAllowedProperty(property: string): boolean {
942
- // Make sure that allowed properties do not interfere with link visibility.
943
- const prefixes = [
944
- 'background',
945
- 'border',
946
- 'color',
947
- 'font',
948
- 'line',
949
- 'margin',
950
- 'padding',
951
- 'text',
952
- '-webkit-background',
953
- '-webkit-border',
954
- '-webkit-font',
955
- '-webkit-margin',
956
- '-webkit-padding',
957
- '-webkit-text',
958
- ];
959
- for (const prefix of prefixes) {
960
- if (property.startsWith(prefix)) {
961
- return true;
883
+ case 'string': {
884
+ if (currentStyle.size === 0) {
885
+ formattedResult.append(this.linkifyStringAsFragment(token.value));
886
+ } else {
887
+ const lines = token.value.split('\n');
888
+ for (let i = 0; i < lines.length; i++) {
889
+ if (i > 0) {
890
+ formattedResult.append(document.createElement('br'));
891
+ }
892
+ const wrapper = document.createElement('span');
893
+ wrapper.style.setProperty('contain', 'paint');
894
+ wrapper.style.setProperty('display', 'inline-block');
895
+ wrapper.style.setProperty('max-width', '100%');
896
+ wrapper.appendChild(this.linkifyStringAsFragment(lines[i]));
897
+ for (const [property, {value, priority}] of currentStyle) {
898
+ wrapper.style.setProperty(property, value, priority);
899
+ }
900
+ formattedResult.append(wrapper);
901
+ }
902
+ }
903
+ break;
962
904
  }
963
- }
964
- return false;
965
- }
966
-
967
- // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
968
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
969
- const formatters: Record<string, Platform.StringUtilities.FormatterFunction<any>> = {};
970
- // Firebug uses %o for formatting objects.
971
- formatters.o = parameterFormatter.bind(this, false /* force */, true /* includePreview */);
972
- formatters.s = stringFormatter;
973
- formatters.f = floatFormatter;
974
- // Firebug allows both %i and %d for formatting integers.
975
- formatters.i = integerFormatter;
976
- formatters.d = integerFormatter;
977
-
978
- // Firebug uses %c for styling the message.
979
- formatters.c = styleFormatter;
980
-
981
- // Support %O to force object formatting, instead of the type-based %o formatting.
982
- formatters.O = parameterFormatter.bind(this, true /* force */, false /* includePreview */);
983
-
984
- formatters._ = bypassFormatter;
985
-
986
- function append(this: ConsoleViewMessage, a: HTMLElement, b?: string|Node): HTMLElement {
987
- if (b instanceof Node) {
988
- a.appendChild(b);
989
- return a;
990
- }
991
- if (typeof b === 'undefined') {
992
- return a;
993
- }
994
- if (!currentStyle) {
995
- a.appendChild(this.linkifyStringAsFragment(String(b)));
996
- return a;
997
- }
998
- const lines = String(b).split('\n');
999
- for (let i = 0; i < lines.length; i++) {
1000
- const line = lines[i];
1001
- const lineFragment = this.linkifyStringAsFragment(line);
1002
- const wrapper = document.createElement('span');
1003
- wrapper.style.setProperty('contain', 'paint');
1004
- wrapper.style.setProperty('display', 'inline-block');
1005
- wrapper.style.setProperty('max-width', '100%');
1006
- wrapper.appendChild(lineFragment);
1007
- applyCurrentStyle(wrapper);
1008
-
1009
- a.appendChild(wrapper);
1010
- if (i < lines.length - 1) {
1011
- a.appendChild(document.createElement('br'));
905
+ case 'style': {
906
+ // Make sure that allowed properties do not interfere with link visibility.
907
+ const ALLOWED_PROPERTY_PREFIXES =
908
+ ['background', 'border', 'color', 'font', 'line', 'margin', 'padding', 'text'];
909
+ currentStyle.clear();
910
+ const buffer = document.createElement('span');
911
+ buffer.setAttribute('style', token.value);
912
+ for (const property of buffer.style) {
913
+ if (!ALLOWED_PROPERTY_PREFIXES.some(
914
+ prefix => property.startsWith(prefix) || property.startsWith(`-webkit-${prefix}`))) {
915
+ continue;
916
+ }
917
+ currentStyle.set(property, {
918
+ value: buffer.style.getPropertyValue(property),
919
+ priority: buffer.style.getPropertyPriority(property),
920
+ });
921
+ }
922
+ break;
1012
923
  }
1013
924
  }
1014
- return a;
1015
925
  }
1016
-
1017
- function applyCurrentStyle(element: HTMLElement): void {
1018
- if (!currentStyle) {
1019
- return;
1020
- }
1021
- for (const [property, {value, priority}] of currentStyle.entries()) {
1022
- element.style.setProperty((property as string), value, priority);
1023
- }
1024
- }
1025
-
1026
- // Platform.StringUtilities.format does treat formattedResult like a Builder, result is an object.
1027
- return Platform.StringUtilities.format(format, parameters, formatters, formattedResult, append.bind(this));
926
+ return args;
1028
927
  }
1029
928
 
1030
929
  matchesFilterRegex(regexObject: RegExp): boolean {
@@ -4,6 +4,7 @@
4
4
 
5
5
  import './ConsoleContextSelector.js';
6
6
  import './ConsoleFilter.js';
7
+ import './ConsoleFormat.js';
7
8
  import './ConsolePinPane.js';
8
9
  import './ConsoleSidebar.js';
9
10
  import './ConsoleViewport.js';
@@ -14,6 +15,7 @@ import './ConsolePanel.js';
14
15
 
15
16
  import * as ConsoleContextSelector from './ConsoleContextSelector.js';
16
17
  import * as ConsoleFilter from './ConsoleFilter.js';
18
+ import * as ConsoleFormat from './ConsoleFormat.js';
17
19
  import * as ConsolePanel from './ConsolePanel.js';
18
20
  import * as ConsolePinPane from './ConsolePinPane.js';
19
21
  import * as ConsolePrompt from './ConsolePrompt.js';
@@ -25,6 +27,7 @@ import * as ConsoleViewport from './ConsoleViewport.js';
25
27
  export {
26
28
  ConsoleContextSelector,
27
29
  ConsoleFilter,
30
+ ConsoleFormat,
28
31
  ConsolePanel,
29
32
  ConsolePinPane,
30
33
  ConsolePrompt,
@@ -4,6 +4,7 @@
4
4
 
5
5
  import * as i18n from '../../../core/i18n/i18n.js';
6
6
  import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js';
7
+ import * as Input from '../../../ui/components/input/input.js';
7
8
  import * as LitHtml from '../../../ui/lit-html/lit-html.js';
8
9
  import adornerSettingsPaneStyles from './adornerSettingsPane.css.js';
9
10
 
@@ -48,7 +49,7 @@ export class AdornerSettingsPane extends HTMLElement {
48
49
  #settings: AdornerSettingsMap = new Map();
49
50
 
50
51
  connectedCallback(): void {
51
- this.#shadow.adoptedStyleSheets = [adornerSettingsPaneStyles];
52
+ this.#shadow.adoptedStyleSheets = [Input.checkboxStyles, adornerSettingsPaneStyles];
52
53
  }
53
54
 
54
55
  set data(data: AdornerSettingsPaneData) {
@@ -13,6 +13,7 @@ import {LayoutElement} from './LayoutPaneUtils.js';
13
13
  import type {NodeTextData} from './NodeText.js';
14
14
  import {NodeText} from './NodeText.js';
15
15
  import layoutPaneStyles from '../layoutPane.css.js';
16
+ import * as Input from '../../../ui/components/input/input.js';
16
17
  // eslint-disable-next-line rulesdir/es_modules_import
17
18
  import inspectorCommonStyles from '../../../ui/legacy/inspectorCommon.css.js';
18
19
 
@@ -103,6 +104,7 @@ export class LayoutPane extends HTMLElement {
103
104
  constructor() {
104
105
  super();
105
106
  this.#shadow.adoptedStyleSheets = [
107
+ Input.checkboxStyles,
106
108
  layoutPaneStyles,
107
109
  inspectorCommonStyles,
108
110
  ];