chrome-devtools-frontend 1.0.954163 → 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.
@@ -845,6 +845,7 @@ grd_files_debug_sources = [
845
845
  "front_end/panels/changes/changesView.css.js",
846
846
  "front_end/panels/console/ConsoleContextSelector.js",
847
847
  "front_end/panels/console/ConsoleFilter.js",
848
+ "front_end/panels/console/ConsoleFormat.js",
848
849
  "front_end/panels/console/ConsolePanel.js",
849
850
  "front_end/panels/console/ConsolePinPane.js",
850
851
  "front_end/panels/console/ConsolePrompt.js",
@@ -290,6 +290,7 @@ export class Setting<V> {
290
290
  // TODO(crbug.com/1172300) Type cannot be inferred without changes to consumers. See above.
291
291
  #serializer: Serializer<unknown, V> = JSON;
292
292
  #hadUserAction?: boolean;
293
+ #disabled?: boolean;
293
294
 
294
295
  constructor(
295
296
  readonly name: string, readonly defaultValue: V, private readonly eventSupport: ObjectWrapper<GenericEvents>,
@@ -333,6 +334,15 @@ export class Setting<V> {
333
334
  this.#requiresUserAction = requiresUserAction;
334
335
  }
335
336
 
337
+ disabled(): boolean {
338
+ return this.#disabled || false;
339
+ }
340
+
341
+ setDisabled(disabled: boolean): void {
342
+ this.#disabled = disabled;
343
+ this.eventSupport.dispatchEventToListeners(this.name);
344
+ }
345
+
336
346
  get(): V {
337
347
  if (this.#requiresUserAction && !this.#hadUserAction) {
338
348
  return this.defaultValue;
@@ -581,12 +581,6 @@
581
581
  "core/sdk/sdk-meta.ts | disableCache": {
582
582
  "message": "Disable cache (while DevTools is open)"
583
583
  },
584
- "core/sdk/sdk-meta.ts | disabledDarkMode": {
585
- "message": "Disable"
586
- },
587
- "core/sdk/sdk-meta.ts | disableEmulateAutoDarkMode": {
588
- "message": "Disable auto dark mode"
589
- },
590
584
  "core/sdk/sdk-meta.ts | disableJavascript": {
591
585
  "message": "Disable JavaScript"
592
586
  },
@@ -617,9 +611,6 @@
617
611
  "core/sdk/sdk-meta.ts | doNotEmulateCssMediaType": {
618
612
  "message": "Do not emulate CSS media type"
619
613
  },
620
- "core/sdk/sdk-meta.ts | doNotEmulateDarkMode": {
621
- "message": "Do not emulate auto dark mode"
622
- },
623
614
  "core/sdk/sdk-meta.ts | doNotExtendGridLines": {
624
615
  "message": "Do not extend grid lines"
625
616
  },
@@ -689,12 +680,6 @@
689
680
  "core/sdk/sdk-meta.ts | enableCustomFormatters": {
690
681
  "message": "Enable custom formatters"
691
682
  },
692
- "core/sdk/sdk-meta.ts | enabledDarkMode": {
693
- "message": "Enable"
694
- },
695
- "core/sdk/sdk-meta.ts | enableEmulateAutoDarkMode": {
696
- "message": "Enable auto dark mode"
697
- },
698
683
  "core/sdk/sdk-meta.ts | enableJavascript": {
699
684
  "message": "Enable JavaScript"
700
685
  },
@@ -947,11 +932,14 @@
947
932
  "entrypoints/inspector_main/RenderingOptions.ts | emulateAFocusedPage": {
948
933
  "message": "Emulate a focused page"
949
934
  },
935
+ "entrypoints/inspector_main/RenderingOptions.ts | emulateAutoDarkMode": {
936
+ "message": "Enable automatic dark mode"
937
+ },
950
938
  "entrypoints/inspector_main/RenderingOptions.ts | emulatesAFocusedPage": {
951
939
  "message": "Emulates a focused page."
952
940
  },
953
941
  "entrypoints/inspector_main/RenderingOptions.ts | emulatesAutoDarkMode": {
954
- "message": "Enables automatic dark mode for the inspected page."
942
+ "message": "Enables automatic dark mode and sets prefers-color-scheme to dark."
955
943
  },
956
944
  "entrypoints/inspector_main/RenderingOptions.ts | forcesCssColorgamutMediaFeature": {
957
945
  "message": "Forces CSS color-gamut media feature"
@@ -581,12 +581,6 @@
581
581
  "core/sdk/sdk-meta.ts | disableCache": {
582
582
  "message": "D̂íŝáb̂ĺê ćâćĥé (ŵh́îĺê D́êv́T̂óôĺŝ íŝ óp̂én̂)"
583
583
  },
584
- "core/sdk/sdk-meta.ts | disabledDarkMode": {
585
- "message": "D̂íŝáb̂ĺê"
586
- },
587
- "core/sdk/sdk-meta.ts | disableEmulateAutoDarkMode": {
588
- "message": "D̂íŝáb̂ĺê áût́ô d́âŕk̂ ḿôd́ê"
589
- },
590
584
  "core/sdk/sdk-meta.ts | disableJavascript": {
591
585
  "message": "D̂íŝáb̂ĺê J́âv́âŚĉŕîṕt̂"
592
586
  },
@@ -617,9 +611,6 @@
617
611
  "core/sdk/sdk-meta.ts | doNotEmulateCssMediaType": {
618
612
  "message": "D̂ó n̂ót̂ ém̂úl̂át̂é ĈŚŜ ḿêd́îá t̂ýp̂é"
619
613
  },
620
- "core/sdk/sdk-meta.ts | doNotEmulateDarkMode": {
621
- "message": "D̂ó n̂ót̂ ém̂úl̂át̂é âút̂ó d̂ár̂ḱ m̂ód̂é"
622
- },
623
614
  "core/sdk/sdk-meta.ts | doNotExtendGridLines": {
624
615
  "message": "D̂ó n̂ót̂ éx̂t́êńd̂ ǵr̂íd̂ ĺîńêś"
625
616
  },
@@ -689,12 +680,6 @@
689
680
  "core/sdk/sdk-meta.ts | enableCustomFormatters": {
690
681
  "message": "Êńâb́l̂é ĉúŝt́ôḿ f̂ór̂ḿât́t̂ér̂ś"
691
682
  },
692
- "core/sdk/sdk-meta.ts | enabledDarkMode": {
693
- "message": "Êńâb́l̂é"
694
- },
695
- "core/sdk/sdk-meta.ts | enableEmulateAutoDarkMode": {
696
- "message": "Êńâb́l̂é âút̂ó d̂ár̂ḱ m̂ód̂é"
697
- },
698
683
  "core/sdk/sdk-meta.ts | enableJavascript": {
699
684
  "message": "Êńâb́l̂é Ĵáv̂áŜćr̂íp̂t́"
700
685
  },
@@ -947,11 +932,14 @@
947
932
  "entrypoints/inspector_main/RenderingOptions.ts | emulateAFocusedPage": {
948
933
  "message": "Êḿûĺât́ê á f̂óĉúŝéd̂ ṕâǵê"
949
934
  },
935
+ "entrypoints/inspector_main/RenderingOptions.ts | emulateAutoDarkMode": {
936
+ "message": "Êńâb́l̂é âút̂óm̂át̂íĉ d́âŕk̂ ḿôd́ê"
937
+ },
950
938
  "entrypoints/inspector_main/RenderingOptions.ts | emulatesAFocusedPage": {
951
939
  "message": "Êḿûĺât́êś â f́ôćûśêd́ p̂áĝé."
952
940
  },
953
941
  "entrypoints/inspector_main/RenderingOptions.ts | emulatesAutoDarkMode": {
954
- "message": "Êńâb́l̂éŝ áût́ôḿât́îć d̂ár̂ḱ m̂ód̂é f̂ór̂ t́é îńŝṕêćt̂éd̂ ṕâǵê."
942
+ "message": "Êńâb́l̂éŝ áût́ôḿât́îć d̂ár̂ḱ m̂ód̂é âńd̂ śêt́ŝ prefers-color-scheme ô dark."
955
943
  },
956
944
  "entrypoints/inspector_main/RenderingOptions.ts | forcesCssColorgamutMediaFeature": {
957
945
  "message": "F̂ór̂ćêś ĈŚŜ color-gamut ḿêd́îá f̂éât́ûŕê"
@@ -26,186 +26,6 @@ export const escapeCharacters = (inputString: string, charsToEscape: string): st
26
26
  return result;
27
27
  };
28
28
 
29
- export const enum FormatterType {
30
- STRING = 'string',
31
- SPECIFIER = 'specifier',
32
- }
33
-
34
- export interface FormatterToken {
35
- type: FormatterType;
36
- value?: string|{description: string};
37
- specifier?: string;
38
- precision?: number;
39
- substitutionIndex?: number;
40
- }
41
-
42
- export const tokenizeFormatString = function(
43
- formatString: string, formatters: Record<string, Function>): FormatterToken[] {
44
- const tokens: FormatterToken[] = [];
45
-
46
- function addStringToken(str: string): void {
47
- if (!str) {
48
- return;
49
- }
50
- if (tokens.length && tokens[tokens.length - 1].type === FormatterType.STRING) {
51
- tokens[tokens.length - 1].value += str;
52
- } else {
53
- tokens.push({
54
- type: FormatterType.STRING,
55
- value: str,
56
- });
57
- }
58
- }
59
-
60
- function addSpecifierToken(specifier: string, precision: number, substitutionIndex: number): void {
61
- tokens.push({type: FormatterType.SPECIFIER, specifier, precision, substitutionIndex, value: undefined});
62
- }
63
-
64
- function addAnsiColor(code: number): void {
65
- type ColorType = 'color'|'colorLight'|'bgColor'|'bgColorLight';
66
-
67
- const types: Record<number, ColorType> = {3: 'color', 9: 'colorLight', 4: 'bgColor', 10: 'bgColorLight'};
68
- const colorCodes = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'lightGray', '', 'default'];
69
- const colorCodesLight =
70
- ['darkGray', 'lightRed', 'lightGreen', 'lightYellow', 'lightBlue', 'lightMagenta', 'lightCyan', 'white', ''];
71
- const colors: Record<ColorType, string[]> =
72
- {color: colorCodes, colorLight: colorCodesLight, bgColor: colorCodes, bgColorLight: colorCodesLight};
73
- const type = types[Math.floor(code / 10)] as ColorType;
74
- if (!type) {
75
- return;
76
- }
77
- const color = colors[type][code % 10];
78
- if (!color) {
79
- return;
80
- }
81
- tokens.push({
82
- type: FormatterType.SPECIFIER,
83
- specifier: 'c',
84
- value: {description: (type.startsWith('bg') ? 'background : ' : 'color: ') + color},
85
- precision: undefined,
86
- substitutionIndex: undefined,
87
- });
88
- }
89
-
90
- let textStart = 0;
91
- let substitutionIndex = 0;
92
- const re =
93
- new RegExp(`%%|%(?:(\\d+)\\$)?(?:\\.(\\d*))?([${Object.keys(formatters).join('')}])|\\u001b\\[(\\d+)m`, 'g');
94
- for (let match = re.exec(formatString); match !== null; match = re.exec(formatString)) {
95
- const matchStart = match.index;
96
- if (matchStart > textStart) {
97
- addStringToken(formatString.substring(textStart, matchStart));
98
- }
99
-
100
- if (match[0] === '%%') {
101
- addStringToken('%');
102
- } else if (match[0].startsWith('%')) {
103
- const [, substitionString, precisionString, specifierString] = match;
104
- if (substitionString && Number(substitionString) > 0) {
105
- substitutionIndex = Number(substitionString) - 1;
106
- }
107
- const precision = precisionString ? Number(precisionString) : -1;
108
- addSpecifierToken(specifierString, precision, substitutionIndex);
109
- ++substitutionIndex;
110
- } else {
111
- const code = Number(match[4]);
112
- addAnsiColor(code);
113
- }
114
- textStart = matchStart + match[0].length;
115
- }
116
- addStringToken(formatString.substring(textStart));
117
- return tokens;
118
- };
119
-
120
- export type FormatterFunction<T> = (input: string|{description: string}|undefined|T, token: FormatterToken) => unknown;
121
-
122
- export const format = function<T, U>(
123
- formatString: string, substitutions: ArrayLike<U>|null, formatters: Record<string, FormatterFunction<U>>,
124
- initialValue: T, append: (initialValue: T, newString: string) => T, tokenizedFormat?: FormatterToken[]): {
125
- formattedResult: T,
126
- unusedSubstitutions: ArrayLike<U>|null,
127
- } {
128
- if (!formatString || ((!substitutions || !substitutions.length) && formatString.search(/\u001b\[(\d+)m/) === -1)) {
129
- return {formattedResult: append(initialValue, formatString), unusedSubstitutions: substitutions};
130
- }
131
-
132
- function prettyFunctionName(): string {
133
- return 'String.format("' + formatString + '", "' + Array.prototype.join.call(substitutions, '", "') + '")';
134
- }
135
-
136
- function warn(msg: string): void {
137
- console.warn(prettyFunctionName() + ': ' + msg);
138
- }
139
-
140
- function error(msg: string): void {
141
- console.error(prettyFunctionName() + ': ' + msg);
142
- }
143
-
144
- let result = initialValue;
145
- const tokens = tokenizedFormat || tokenizeFormatString(formatString, formatters);
146
- const usedSubstitutionIndexes: Record<number, boolean> = {};
147
- const actualSubstitutions: ArrayLike<U> = substitutions || [];
148
-
149
- for (const token of tokens) {
150
- if (token.type === FormatterType.STRING) {
151
- result = append(result, token.value as string);
152
- continue;
153
- }
154
-
155
- if (token.type !== FormatterType.SPECIFIER) {
156
- error('Unknown token type "' + token.type + '" found.');
157
- continue;
158
- }
159
-
160
- if (!token.value && token.substitutionIndex !== undefined &&
161
- token.substitutionIndex >= actualSubstitutions.length) {
162
- // If there are not enough substitutions for the current substitutionIndex
163
- // just output the format specifier literally and move on.
164
- error(
165
- 'not enough substitution arguments. Had ' + actualSubstitutions.length + ' but needed ' +
166
- (token.substitutionIndex + 1) + ', so substitution was skipped.');
167
- result = append(
168
- result,
169
- '%' + ((token.precision !== undefined && token.precision > -1) ? token.precision : '') + token.specifier);
170
- continue;
171
- }
172
-
173
- if (!token.value && token.substitutionIndex !== undefined) {
174
- usedSubstitutionIndexes[token.substitutionIndex] = true;
175
- }
176
-
177
- if (token.specifier === undefined || !(token.specifier in formatters)) {
178
- // Encountered an unsupported format character, treat as a string.
179
- warn('unsupported format character \u201C' + token.specifier + '\u201D. Treating as a string.');
180
- const stringToAppend = (token.value || token.substitutionIndex === undefined) ?
181
- '' :
182
- String(actualSubstitutions[token.substitutionIndex]);
183
- result = append(result, stringToAppend);
184
- continue;
185
- }
186
-
187
- const formatter = formatters[token.specifier];
188
- const valueToFormat = token.value ||
189
- (token.substitutionIndex !== undefined ? actualSubstitutions[token.substitutionIndex] : undefined);
190
- const stringToAppend = formatter(valueToFormat, token);
191
-
192
- result = append(
193
- result,
194
- stringToAppend as string,
195
- );
196
- }
197
-
198
- const unusedSubstitutions = [];
199
- for (let i = 0; i < actualSubstitutions.length; ++i) {
200
- if (i in usedSubstitutionIndexes) {
201
- continue;
202
- }
203
- unusedSubstitutions.push(actualSubstitutions[i]);
204
- }
205
-
206
- return {formattedResult: result, unusedSubstitutions: unusedSubstitutions};
207
- };
208
-
209
29
  const toHexadecimal = (charCode: number, padToLength: number): string => {
210
30
  return charCode.toString(16).toUpperCase().padStart(padToLength, '0');
211
31
  };
@@ -126,9 +126,16 @@ export class EmulationModel extends SDKModel<void> {
126
126
  this.updateCssMedia();
127
127
 
128
128
  const autoDarkModeSetting = Common.Settings.Settings.instance().moduleSetting('emulateAutoDarkMode');
129
- autoDarkModeSetting.addChangeListener(() => this.emulateAutoDarkMode(autoDarkModeSetting.get()));
129
+ autoDarkModeSetting.addChangeListener(() => {
130
+ const enabled = autoDarkModeSetting.get();
131
+ mediaFeaturePrefersColorSchemeSetting.setDisabled(enabled);
132
+ mediaFeaturePrefersColorSchemeSetting.set(enabled ? 'dark' : '');
133
+ this.emulateAutoDarkMode(enabled);
134
+ });
130
135
  if (autoDarkModeSetting.get()) {
131
- this.emulateAutoDarkMode(autoDarkModeSetting.get());
136
+ mediaFeaturePrefersColorSchemeSetting.setDisabled(true);
137
+ mediaFeaturePrefersColorSchemeSetting.set('dark');
138
+ this.emulateAutoDarkMode(true);
132
139
  }
133
140
 
134
141
  const visionDeficiencySetting = Common.Settings.Settings.instance().moduleSetting('emulatedVisionDeficiency');
@@ -277,22 +284,14 @@ export class EmulationModel extends SDKModel<void> {
277
284
  }
278
285
  }
279
286
 
280
- private static parseAutoDarkModeSetting(setting: string): boolean|undefined {
281
- switch (setting) {
282
- case 'default':
283
- return undefined;
284
- case 'enabled':
285
- return true;
286
- case 'disabled':
287
- return false;
288
- default:
289
- throw Error('unrecognized auto dark mode setting');
287
+ private async emulateAutoDarkMode(enabled: boolean): Promise<void> {
288
+ if (enabled) {
289
+ this.#mediaConfiguration.set('prefers-color-scheme', 'dark');
290
+ await this.updateCssMedia();
290
291
  }
291
- }
292
-
293
- private async emulateAutoDarkMode(setting: string): Promise<void> {
294
- const enabled = EmulationModel.parseAutoDarkModeSetting(setting);
295
- await this.#emulationAgent.invoke_setAutoDarkModeOverride({enabled});
292
+ // We never send `enabled: false` since that would explicitly disable
293
+ // autodark mode. We either enable it or clear any existing override.
294
+ await this.#emulationAgent.invoke_setAutoDarkModeOverride({enabled: enabled || undefined});
296
295
  }
297
296
 
298
297
  private async emulateVisionDeficiency(type: Protocol.Emulation.SetEmulatedVisionDeficiencyRequestType):
@@ -360,7 +359,7 @@ export class EmulationModel extends SDKModel<void> {
360
359
  {enabled: configuration.enabled, configuration: configuration.configuration});
361
360
  }
362
361
 
363
- private updateCssMedia(): void {
362
+ private async updateCssMedia(): Promise<void> {
364
363
  // See the note above, where this.#mediaConfiguration is defined.
365
364
  const type = this.#mediaConfiguration.get('type') ?? '';
366
365
  const features = [
@@ -389,7 +388,7 @@ export class EmulationModel extends SDKModel<void> {
389
388
  value: this.#mediaConfiguration.get('prefers-reduced-motion') ?? '',
390
389
  },
391
390
  ];
392
- this.emulateCSSMedia(type, features);
391
+ return this.emulateCSSMedia(type, features);
393
392
  }
394
393
  }
395
394
 
@@ -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),
@@ -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
  `}
@@ -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,
@@ -104,13 +104,17 @@ export class SizeInputElement extends HTMLElement {
104
104
  }
105
105
 
106
106
  #handleModifierKeys(event: Event): void {
107
- const modifiedValue = UILegacy.UIUtils.modifiedFloatNumber(getInputValue(event), event);
107
+ let modifiedValue = UILegacy.UIUtils.modifiedFloatNumber(getInputValue(event), event);
108
108
  if (modifiedValue === null) {
109
109
  return;
110
110
  }
111
111
 
112
+ modifiedValue = Math.min(modifiedValue, EmulationModel.DeviceModeModel.MaxDeviceSize);
113
+ modifiedValue = Math.max(modifiedValue, EmulationModel.DeviceModeModel.MinDeviceSize);
114
+
112
115
  event.preventDefault();
113
116
  (event.target as HTMLInputElement).value = String(modifiedValue);
117
+ this.dispatchEvent(new SizeChangedEvent(modifiedValue));
114
118
  }
115
119
  }
116
120
 
@@ -56,8 +56,9 @@ export class SettingCheckbox extends HTMLElement {
56
56
  LitHtml.html`
57
57
  <p>
58
58
  <label>
59
- <input type="checkbox" ?checked=${this.#setting.get()} ?disabled=${this.#disabled} @change=${
60
- this.#checkboxChanged} aria-label=${this.#setting.title()} /> ${this.#setting.title()}
59
+ <input type="checkbox" ?checked=${this.#setting.get()} ?disabled=${
60
+ this.#disabled || this.#setting.disabled()} @change=${this.#checkboxChanged} aria-label=${
61
+ this.#setting.title()} /> ${this.#setting.title()}
61
62
  </label>
62
63
  </p>`,
63
64
  this.#shadow, {host: this});
@@ -110,6 +110,7 @@ const createSettingSelect = function(
110
110
  select.selectedIndex = i;
111
111
  }
112
112
  }
113
+ select.disabled = setting.disabled();
113
114
  }
114
115
 
115
116
  function selectChanged(): void {
package/package.json CHANGED
@@ -53,5 +53,5 @@
53
53
  "unittest": "scripts/test/run_unittests.py --no-text-coverage",
54
54
  "watch": "third_party/node/node.py --output scripts/watch_build.js"
55
55
  },
56
- "version": "1.0.954163"
56
+ "version": "1.0.954271"
57
57
  }