chrome-devtools-frontend 1.0.1025175 → 1.0.1026673
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.
- package/config/gni/devtools_grd_files.gni +1 -0
- package/config/gni/devtools_image_files.gni +1 -0
- package/docs/triage_guidelines.md +1 -122
- package/front_end/Images/src/star_outline.svg +3 -0
- package/front_end/core/common/ResourceType.ts +1 -0
- package/front_end/core/i18n/locales/en-US.json +18 -0
- package/front_end/core/i18n/locales/en-XL.json +18 -0
- package/front_end/core/sdk/DOMModel.ts +5 -0
- package/front_end/core/sdk/SourceMap.ts +22 -6
- package/front_end/entrypoints/lighthouse_worker/LighthouseWorkerService.ts +6 -3
- package/front_end/generated/InspectorBackendCommands.js +5 -3
- package/front_end/generated/SupportedCSSProperties.js +11 -0
- package/front_end/generated/protocol-mapping.d.ts +14 -0
- package/front_end/generated/protocol-proxy-api.d.ts +10 -0
- package/front_end/generated/protocol.ts +67 -0
- package/front_end/legacy_test_runner/sources_test_runner/DebuggerTestRunner.js +1 -1
- package/front_end/models/bindings/CompilerScriptMapping.ts +1 -1
- package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +7 -1
- package/front_end/models/bindings/IgnoreListManager.ts +18 -20
- package/front_end/models/issues_manager/descriptions/arAttributionUntrustworthyOrigin.md +3 -3
- package/front_end/models/issues_manager/descriptions/clientHintMetaTagAllowListInvalidOrigin.md +1 -1
- package/front_end/models/issues_manager/descriptions/clientHintMetaTagModifiedHTML.md +1 -1
- package/front_end/models/javascript_metadata/NativeFunctions.js +79 -67
- package/front_end/models/source_map_scopes/NamesResolver.ts +34 -0
- package/front_end/models/text_utils/TextRange.ts +8 -0
- package/front_end/models/timeline_model/TimelineModel.ts +18 -1
- package/front_end/panels/elements/ElementsTreeOutline.ts +18 -34
- package/front_end/panels/elements/TopLayerContainer.ts +51 -29
- package/front_end/panels/elements/elementsTreeOutline.css +1 -1
- package/front_end/panels/lighthouse/LighthouseController.ts +3 -0
- package/front_end/panels/network/NetworkDataGridNode.ts +1 -2
- package/front_end/panels/profiler/ProfilesPanel.ts +1 -0
- package/front_end/panels/security/SecurityPanel.ts +52 -0
- package/front_end/panels/security/originView.css +1 -1
- package/front_end/panels/sources/CallStackSidebarPane.ts +45 -16
- package/front_end/panels/sources/DebuggerPlugin.ts +2 -2
- package/front_end/panels/sources/callStackSidebarPane.css +15 -9
- package/front_end/panels/sources/navigatorTree.css +3 -3
- package/front_end/panels/sources/watchExpressionsSidebarPane.css +6 -0
- package/front_end/panels/timeline/TimelineFlameChartDataProvider.ts +1 -1
- package/front_end/ui/components/docs/building-ui-documentation/CreatingComponents.md +172 -1
- package/front_end/ui/components/text_editor/TextEditor.ts +3 -0
- package/front_end/ui/legacy/components/data_grid/dataGrid.css +2 -1
- package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +3 -2
- package/front_end/ui/legacy/components/object_ui/objectPropertiesSection.css +6 -1
- package/front_end/ui/legacy/components/utils/JSPresentationUtils.ts +5 -4
- package/package.json +1 -1
@@ -78,9 +78,11 @@ Each component defines a `#render` method which is responsible for invoking LitH
|
|
78
78
|
The `#render` method calls `LitHtml.render`, building up a template with `LitHtml.html`:
|
79
79
|
|
80
80
|
```ts
|
81
|
-
LitHtml.render(LitHtml.html
|
81
|
+
LitHtml.render(LitHtml.html`<p>hello world!</p>`, this.#shadow, {host: this});
|
82
82
|
```
|
83
83
|
|
84
|
+
The third argument (`{host: this}`) tells LitHtml to automatically bind event listeners to the component. This can save you some painful debugging where event listeners do not have the right `this` reference; so we enforce the use of `{host: this}` via a custom ESLint rule.
|
85
|
+
|
84
86
|
There is unfortunately a [clang-format bug](crbug.com/1079231) which makes its auto-formatting of LitHtml templates very unreadable, so we usually disable clang-format round the call:
|
85
87
|
|
86
88
|
```ts
|
@@ -110,3 +112,172 @@ void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
|
|
110
112
|
```
|
111
113
|
|
112
114
|
> `scheduleRender` returns a promise; we use the `void` keyword to instruct TypeScript that we are purposefully not using `await` to wait for the promise to resolve. When scheduling a render it's most common to "fire and forget".
|
115
|
+
|
116
|
+
To summarise, most components start off life looking like:
|
117
|
+
|
118
|
+
```ts
|
119
|
+
export class ElementsBreadcrumbs extends HTMLElement {
|
120
|
+
static readonly litTagName = LitHtml.literal`devtools-chrome-link`;
|
121
|
+
readonly #shadow = this.attachShadow({mode: 'open'});
|
122
|
+
readonly #boundRender = this.#render.bind(this);
|
123
|
+
|
124
|
+
#render(): void {
|
125
|
+
LitHtml.render(LitHtml.html``, this.#shadow, {host:this});
|
126
|
+
}
|
127
|
+
}
|
128
|
+
```
|
129
|
+
|
130
|
+
## Triggering a render
|
131
|
+
|
132
|
+
One of the most important aspects to understand about our component system is that **rendering does not happen automatically**.
|
133
|
+
|
134
|
+
To ensure we trigger a render once the component is added to the DOM, we can define [`connectedCallback`](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#:~:text=lifecycle.%20For%20example%2C-,connectedCallback,-is%20invoked%20each):
|
135
|
+
|
136
|
+
```ts
|
137
|
+
export class ElementsBreadcrumbs extends HTMLElement {
|
138
|
+
static readonly litTagName = LitHtml.literal`devtools-chrome-link`;
|
139
|
+
readonly #shadow = this.attachShadow({mode: 'open'});
|
140
|
+
readonly #boundRender = this.#render.bind(this);
|
141
|
+
|
142
|
+
connectedCallback(): void {
|
143
|
+
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
|
144
|
+
}
|
145
|
+
|
146
|
+
#render(): void {
|
147
|
+
LitHtml.render(LitHtml.html``, this.#shadow, {host:this});
|
148
|
+
}
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
152
|
+
## Passing data into a component
|
153
|
+
|
154
|
+
Most of our components will require data that is passed into them. For example, `ElementsBreadcrumbs` takes in an array of `DOMNode` objects.
|
155
|
+
|
156
|
+
To provide a component some data, we define a `data` setter. This setter takes an object with any data the component requires. This object should have a TypeScript interface defined for it:
|
157
|
+
|
158
|
+
```ts
|
159
|
+
export interface ElementsBreadcrumbsData {
|
160
|
+
selectedNode: DOMNode|null;
|
161
|
+
crumbs: DOMNode[];
|
162
|
+
}
|
163
|
+
|
164
|
+
export class ElementsBreadcrumbs extends HTMLElement {
|
165
|
+
// ...
|
166
|
+
#crumbs: DOMNode[] = [];
|
167
|
+
#selectedNode: DOMNode|null = null;
|
168
|
+
|
169
|
+
set data(data: ElementsBreadcrumbsData) {
|
170
|
+
this.#crumbs = data.crumbs;
|
171
|
+
this.#selectedNode = data.selectedNode;
|
172
|
+
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
```
|
176
|
+
|
177
|
+
## Rendering components
|
178
|
+
|
179
|
+
Now we know how to create components that can take data, let's render them!
|
180
|
+
|
181
|
+
### From a DevTools Widget
|
182
|
+
|
183
|
+
If you are rendering a component from the DevTools widget system, you should instantiate the component, pass any `data` to it, and then append it into the DOM:
|
184
|
+
|
185
|
+
```ts
|
186
|
+
// Within a Widget
|
187
|
+
const breadcrumbs = new ElementsBreadcrumbs();
|
188
|
+
breadcrumbs.data = {selectedNode: node, crumbs: [...]};
|
189
|
+
this.appendChild(breadcrumbs);
|
190
|
+
```
|
191
|
+
|
192
|
+
### From another component
|
193
|
+
|
194
|
+
If you are rendering a component from within another component, render it within the call to `LitHtml.html` and use the static `litTagName` property:
|
195
|
+
|
196
|
+
```ts
|
197
|
+
// Within some component
|
198
|
+
LitHtml.render(LitHtml.html`
|
199
|
+
<${ElementsBreadcrumbs.litTagName}></${ElementsBreadcrumbs>
|
200
|
+
`, this.#shadow, {host: this});
|
201
|
+
```
|
202
|
+
|
203
|
+
To pass data, we use [LitHtml's dot syntax](https://lit.dev/docs/templates/expressions/#property-expressions) to set the `data` property (and invoke our `set data` setter):
|
204
|
+
|
205
|
+
```ts
|
206
|
+
// Within some component
|
207
|
+
LitHtml.render(LitHtml.html`
|
208
|
+
<${ElementsBreadcrumbs.litTagName} .data=${{
|
209
|
+
selectedNode: node,
|
210
|
+
crumbs: [...],
|
211
|
+
}}>
|
212
|
+
</${ElementsBreadcrumbs>
|
213
|
+
`, this.#shadow, {host: this});
|
214
|
+
```
|
215
|
+
|
216
|
+
To enforce some type safety, we also use TypeScript's `as` keyword to force the compiler to type-check the `data` object against the interface:
|
217
|
+
|
218
|
+
```ts
|
219
|
+
// Within some component
|
220
|
+
LitHtml.render(LitHtml.html`
|
221
|
+
<${ElementsBreadcrumbs.litTagName} .data=${{
|
222
|
+
selectedNode: node,
|
223
|
+
crumbs: [...],
|
224
|
+
} as ElementsBreadcrumbsData}>
|
225
|
+
</${ElementsBreadcrumbs>
|
226
|
+
`, this.#shadow, {host: this});
|
227
|
+
```
|
228
|
+
|
229
|
+
This type-checking requirement is enforced by an ESLint rule.
|
230
|
+
|
231
|
+
## Performance concerns with data passing
|
232
|
+
|
233
|
+
The approach of `set data(data)` was chosen because:
|
234
|
+
|
235
|
+
1. It requires few lines of code.
|
236
|
+
2. It provides some form of type safety via the `as FooData` check.
|
237
|
+
3. At the time we didn't have a solution for scheduled and batched renders, and didn't want multiple setters to trigger multiple unnecessary renders.
|
238
|
+
|
239
|
+
However, using `set data(data)` does come with some negative performance costs:
|
240
|
+
|
241
|
+
1. LitHtml will always think the value has changed, because it's an object. If a component renders twice with `.data=${{name: 'Jack'}}`, Lit will think that the value has changed because it's a new object, even though we can see it's holding the same data.
|
242
|
+
2. This approach causes these objects to be created (and subsequently garbage collected) on/after each render.
|
243
|
+
|
244
|
+
For most components in DevTools, these trade-offs are acceptable, and we prefer the type-safety of `set data` and take the usually imperceivable performance hit. However, in rare circumstances, this performance hit is noticeable. A good example of this is in Performance Insights, where we have to constantly re-render components as the user scrolls through their performance timeline. We noticed that this caused a large amount of garbage collection from all the objects being created per-render and then immediately disposed.
|
245
|
+
|
246
|
+
For these situations, we can instead move to an approach where we set properties individually. We still define the interface as before, and then define an individual setter for each property:
|
247
|
+
|
248
|
+
```ts
|
249
|
+
interface ElementsBreadcrumbsData {
|
250
|
+
selectedNode: DOMNode|null;
|
251
|
+
crumbs: DOMNode[];
|
252
|
+
}
|
253
|
+
|
254
|
+
class ElementsBreadcrumbs extends HTMLElement {
|
255
|
+
#crumbs: DOMNode[] = [];
|
256
|
+
#selectedNode: DOMNode|null = null;
|
257
|
+
|
258
|
+
set crumbs(crumbs: ElementsBreadcrumbsData['crumbs']) {
|
259
|
+
this.#crumbs = crumbs;
|
260
|
+
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
|
261
|
+
}
|
262
|
+
|
263
|
+
set selectedNode(selectedNode: ElementsBreadcrumbsData['selectedNode']) {
|
264
|
+
this.#selectedNode = selectedNode;
|
265
|
+
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
```
|
269
|
+
|
270
|
+
Rendering this component within another Lit component would now be done like so:
|
271
|
+
|
272
|
+
```ts
|
273
|
+
// Within some component
|
274
|
+
LitHtml.render(LitHtml.html`
|
275
|
+
<${ElementsBreadcrumbs.litTagName} .crumbs=${[...]} .selectedNode=${node}>
|
276
|
+
</${ElementsBreadcrumbs>
|
277
|
+
`, this.#shadow, {host: this});
|
278
|
+
```
|
279
|
+
|
280
|
+
This solution is more performant, but less type-safe as TypeScript has no means of checking those values. This is something we may rectify using the `as` pattern, but for now it's preferred to use the `set data` method by default.
|
281
|
+
|
282
|
+
|
283
|
+
|
@@ -105,6 +105,9 @@ export class TextEditor extends HTMLElement {
|
|
105
105
|
connectedCallback(): void {
|
106
106
|
if (!this.#activeEditor) {
|
107
107
|
this.#createEditor();
|
108
|
+
} else {
|
109
|
+
this.#activeEditor.scrollDOM.scrollTop = this.#lastScrollPos.top;
|
110
|
+
this.#activeEditor.scrollDOM.scrollLeft = this.#lastScrollPos.left;
|
108
111
|
}
|
109
112
|
}
|
110
113
|
|
@@ -1124,7 +1124,7 @@ export class ObjectPropertyTreeElement extends UI.TreeOutline.TreeElement {
|
|
1124
1124
|
if (this.property.webIdl?.applicable) {
|
1125
1125
|
const icon = new IconButton.Icon.Icon();
|
1126
1126
|
icon.data = {
|
1127
|
-
iconName: '
|
1127
|
+
iconName: 'star_outline',
|
1128
1128
|
color: 'var(--color-text-secondary)',
|
1129
1129
|
width: '16px',
|
1130
1130
|
height: '16px',
|
@@ -1140,7 +1140,8 @@ export class ObjectPropertyTreeElement extends UI.TreeOutline.TreeElement {
|
|
1140
1140
|
`;
|
1141
1141
|
} else {
|
1142
1142
|
container = UI.Fragment.html`
|
1143
|
-
<span class='name-and-value'>${adorner}${this.nameElement}
|
1143
|
+
<span class='name-and-value'>${adorner}${this.nameElement}<span class='separator'>: </span>${
|
1144
|
+
this.valueElement}</span>
|
1144
1145
|
`;
|
1145
1146
|
}
|
1146
1147
|
|
@@ -70,7 +70,7 @@ function populateContextMenu(link: Element, event: Event): void {
|
|
70
70
|
const uiLocation = Linkifier.uiLocation(link);
|
71
71
|
if (uiLocation &&
|
72
72
|
Bindings.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(uiLocation.uiSourceCode)) {
|
73
|
-
if (Bindings.IgnoreListManager.IgnoreListManager.instance().
|
73
|
+
if (Bindings.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(uiLocation.uiSourceCode.url())) {
|
74
74
|
contextMenu.debugSection().appendItem(
|
75
75
|
i18nString(UIStrings.removeFromIgnore),
|
76
76
|
() => Bindings.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(
|
@@ -127,8 +127,8 @@ export function buildStackTraceRows(
|
|
127
127
|
// TODO(crbug.com/1183325): fix race condition with uiLocation still being null here
|
128
128
|
const uiLocation = Linkifier.uiLocation(link);
|
129
129
|
if (uiLocation &&
|
130
|
-
Bindings.IgnoreListManager.IgnoreListManager.instance().
|
131
|
-
uiLocation.uiSourceCode)) {
|
130
|
+
Bindings.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(
|
131
|
+
uiLocation.uiSourceCode.url())) {
|
132
132
|
ignoreListHide = true;
|
133
133
|
}
|
134
134
|
// Linkifier is using a workaround with the 'zero width space' (\u200b).
|
@@ -175,7 +175,8 @@ function updateHiddenRows(
|
|
175
175
|
if ('link' in row && row.link) {
|
176
176
|
const uiLocation = Linkifier.uiLocation(row.link);
|
177
177
|
if (uiLocation &&
|
178
|
-
Bindings.IgnoreListManager.IgnoreListManager.instance().
|
178
|
+
Bindings.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(
|
179
|
+
uiLocation.uiSourceCode.url())) {
|
179
180
|
row.ignoreListHide = true;
|
180
181
|
}
|
181
182
|
if (row.rowCountHide || row.ignoreListHide) {
|
package/package.json
CHANGED