chrome-devtools-frontend 1.0.939144 → 1.0.939277
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.
|
@@ -47,6 +47,7 @@ import {CSSStyleDeclaration, Type} from './CSSStyleDeclaration.js';
|
|
|
47
47
|
import {CSSStyleSheetHeader} from './CSSStyleSheetHeader.js';
|
|
48
48
|
import type {DOMNode} from './DOMModel.js';
|
|
49
49
|
import {DOMModel} from './DOMModel.js';
|
|
50
|
+
import type {ResourceTreeFrame} from './ResourceTreeModel.js';
|
|
50
51
|
import {Events as ResourceTreeModelEvents, ResourceTreeModel} from './ResourceTreeModel.js';
|
|
51
52
|
import type {Target} from './Target.js';
|
|
52
53
|
import {Capability} from './Target.js';
|
|
@@ -54,37 +55,37 @@ import {SDKModel} from './SDKModel.js';
|
|
|
54
55
|
import {SourceMapManager} from './SourceMapManager.js';
|
|
55
56
|
|
|
56
57
|
export class CSSModel extends SDKModel<EventTypes> {
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
readonly #
|
|
61
|
-
readonly #sourceMapManagerInternal: SourceMapManager<CSSStyleSheetHeader>;
|
|
62
|
-
agent: ProtocolProxyApi.CSSApi;
|
|
63
|
-
readonly #styleLoader: ComputedStyleLoader;
|
|
58
|
+
readonly agent: ProtocolProxyApi.CSSApi;
|
|
59
|
+
readonly #domModel: DOMModel;
|
|
60
|
+
readonly #fontFaces: Map<string, CSSFontFace>;
|
|
61
|
+
readonly #originalStyleSheetText: Map<CSSStyleSheetHeader, Promise<string|null>>;
|
|
64
62
|
readonly #resourceTreeModel: ResourceTreeModel|null;
|
|
65
|
-
#
|
|
63
|
+
readonly #sourceMapManager: SourceMapManager<CSSStyleSheetHeader>;
|
|
64
|
+
readonly #styleLoader: ComputedStyleLoader;
|
|
65
|
+
readonly #stylePollingThrottler: Common.Throttler.Throttler;
|
|
66
66
|
readonly #styleSheetIdsForURL: Map<string, Map<string, Set<Protocol.CSS.StyleSheetId>>>;
|
|
67
|
-
readonly #
|
|
68
|
-
#
|
|
69
|
-
|
|
67
|
+
readonly #styleSheetIdToHeader: Map<Protocol.CSS.StyleSheetId, CSSStyleSheetHeader>;
|
|
68
|
+
#cachedMatchedCascadeNode: DOMNode|null;
|
|
69
|
+
#cachedMatchedCascadePromise: Promise<CSSMatchedStyles|null>|null;
|
|
70
70
|
#cssPropertyTracker: CSSPropertyTracker|null;
|
|
71
71
|
#isCSSPropertyTrackingEnabled: boolean;
|
|
72
|
+
#isEnabled: boolean;
|
|
73
|
+
#isRuleUsageTrackingEnabled: boolean;
|
|
72
74
|
#isTrackingRequestPending: boolean;
|
|
73
|
-
readonly #trackedCSSProperties: Map<number, Protocol.CSS.CSSComputedStyleProperty[]>;
|
|
74
|
-
readonly #stylePollingThrottler: Common.Throttler.Throttler;
|
|
75
75
|
|
|
76
76
|
constructor(target: Target) {
|
|
77
77
|
super(target);
|
|
78
|
-
this.#
|
|
78
|
+
this.#isEnabled = false;
|
|
79
79
|
this.#cachedMatchedCascadeNode = null;
|
|
80
80
|
this.#cachedMatchedCascadePromise = null;
|
|
81
|
-
this.#
|
|
82
|
-
this.#
|
|
81
|
+
this.#domModel = (target.model(DOMModel) as DOMModel);
|
|
82
|
+
this.#sourceMapManager = new SourceMapManager(target);
|
|
83
83
|
this.agent = target.cssAgent();
|
|
84
84
|
this.#styleLoader = new ComputedStyleLoader(this);
|
|
85
85
|
this.#resourceTreeModel = target.model(ResourceTreeModel);
|
|
86
86
|
if (this.#resourceTreeModel) {
|
|
87
|
-
this.#resourceTreeModel.addEventListener(
|
|
87
|
+
this.#resourceTreeModel.addEventListener(
|
|
88
|
+
ResourceTreeModelEvents.MainFrameNavigated, this.onMainFrameNavigated, this);
|
|
88
89
|
}
|
|
89
90
|
target.registerCSSDispatcher(new CSSDispatcher(this));
|
|
90
91
|
if (!target.suspended()) {
|
|
@@ -93,23 +94,21 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
93
94
|
this.#styleSheetIdToHeader = new Map();
|
|
94
95
|
this.#styleSheetIdsForURL = new Map();
|
|
95
96
|
|
|
96
|
-
this.#
|
|
97
|
+
this.#originalStyleSheetText = new Map();
|
|
97
98
|
|
|
98
99
|
this.#isRuleUsageTrackingEnabled = false;
|
|
99
100
|
|
|
100
|
-
this.#
|
|
101
|
+
this.#fontFaces = new Map();
|
|
101
102
|
|
|
102
103
|
this.#cssPropertyTracker = null; // TODO: support multiple trackers when we refactor the backend
|
|
103
104
|
this.#isCSSPropertyTrackingEnabled = false;
|
|
104
105
|
this.#isTrackingRequestPending = false;
|
|
105
|
-
this.#trackedCSSProperties = new Map();
|
|
106
106
|
this.#stylePollingThrottler = new Common.Throttler.Throttler(StylePollingInterval);
|
|
107
107
|
|
|
108
|
-
this.#
|
|
109
|
-
Common.Settings.Settings.instance().moduleSetting('cssSourceMapsEnabled').get());
|
|
108
|
+
this.#sourceMapManager.setEnabled(Common.Settings.Settings.instance().moduleSetting('cssSourceMapsEnabled').get());
|
|
110
109
|
Common.Settings.Settings.instance()
|
|
111
110
|
.moduleSetting('cssSourceMapsEnabled')
|
|
112
|
-
.addChangeListener(event => this.#
|
|
111
|
+
.addChangeListener(event => this.#sourceMapManager.setEnabled((event.data as boolean)));
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
headersForSourceURL(sourceURL: string): CSSStyleSheetHeader[] {
|
|
@@ -148,7 +147,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
sourceMapManager(): SourceMapManager<CSSStyleSheetHeader> {
|
|
151
|
-
return this.#
|
|
150
|
+
return this.#sourceMapManager;
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
static trimSourceURL(text: string): string {
|
|
@@ -172,7 +171,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
domModel(): DOMModel {
|
|
175
|
-
return this.#
|
|
174
|
+
return this.#domModel;
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
async setStyleText(
|
|
@@ -187,7 +186,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
187
186
|
return false;
|
|
188
187
|
}
|
|
189
188
|
|
|
190
|
-
this.#
|
|
189
|
+
this.#domModel.markUndoableState(!majorChange);
|
|
191
190
|
const edit = new Edit(styleSheetId, range, text, styles[0]);
|
|
192
191
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
193
192
|
return true;
|
|
@@ -207,7 +206,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
207
206
|
if (!selectorList) {
|
|
208
207
|
return false;
|
|
209
208
|
}
|
|
210
|
-
this.#
|
|
209
|
+
this.#domModel.markUndoableState();
|
|
211
210
|
const edit = new Edit(styleSheetId, range, text, selectorList);
|
|
212
211
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
213
212
|
return true;
|
|
@@ -227,7 +226,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
227
226
|
if (!keyText) {
|
|
228
227
|
return false;
|
|
229
228
|
}
|
|
230
|
-
this.#
|
|
229
|
+
this.#domModel.markUndoableState();
|
|
231
230
|
const edit = new Edit(styleSheetId, range, text, keyText);
|
|
232
231
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
233
232
|
return true;
|
|
@@ -268,12 +267,12 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
268
267
|
}
|
|
269
268
|
|
|
270
269
|
isEnabled(): boolean {
|
|
271
|
-
return this.#
|
|
270
|
+
return this.#isEnabled;
|
|
272
271
|
}
|
|
273
272
|
|
|
274
273
|
private async enable(): Promise<void> {
|
|
275
274
|
await this.agent.invoke_enable();
|
|
276
|
-
this.#
|
|
275
|
+
this.#isEnabled = true;
|
|
277
276
|
if (this.#isRuleUsageTrackingEnabled) {
|
|
278
277
|
await this.startCoverage();
|
|
279
278
|
}
|
|
@@ -287,7 +286,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
287
286
|
return null;
|
|
288
287
|
}
|
|
289
288
|
|
|
290
|
-
const node = this.#
|
|
289
|
+
const node = this.#domModel.nodeForId(nodeId);
|
|
291
290
|
if (!node) {
|
|
292
291
|
return null;
|
|
293
292
|
}
|
|
@@ -399,7 +398,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
399
398
|
if (!media) {
|
|
400
399
|
return false;
|
|
401
400
|
}
|
|
402
|
-
this.#
|
|
401
|
+
this.#domModel.markUndoableState();
|
|
403
402
|
const edit = new Edit(styleSheetId, range, newMediaText, media);
|
|
404
403
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
405
404
|
return true;
|
|
@@ -421,7 +420,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
421
420
|
if (!containerQuery) {
|
|
422
421
|
return false;
|
|
423
422
|
}
|
|
424
|
-
this.#
|
|
423
|
+
this.#domModel.markUndoableState();
|
|
425
424
|
const edit = new Edit(styleSheetId, range, newContainerQueryText, containerQuery);
|
|
426
425
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
427
426
|
return true;
|
|
@@ -439,7 +438,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
439
438
|
if (!rule) {
|
|
440
439
|
return null;
|
|
441
440
|
}
|
|
442
|
-
this.#
|
|
441
|
+
this.#domModel.markUndoableState();
|
|
443
442
|
const edit = new Edit(styleSheetId, ruleLocation, ruleText, rule);
|
|
444
443
|
this.fireStyleSheetChanged(styleSheetId, edit);
|
|
445
444
|
return new CSSStyleRule(this, rule);
|
|
@@ -477,13 +476,13 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
477
476
|
|
|
478
477
|
fontsUpdated(fontFace?: Protocol.CSS.FontFace|null): void {
|
|
479
478
|
if (fontFace) {
|
|
480
|
-
this.#
|
|
479
|
+
this.#fontFaces.set(fontFace.src, new CSSFontFace(fontFace));
|
|
481
480
|
}
|
|
482
481
|
this.dispatchEventToListeners(Events.FontsUpdated);
|
|
483
482
|
}
|
|
484
483
|
|
|
485
484
|
fontFaces(): CSSFontFace[] {
|
|
486
|
-
return [...this.#
|
|
485
|
+
return [...this.#fontFaces.values()];
|
|
487
486
|
}
|
|
488
487
|
|
|
489
488
|
styleSheetHeaderForId(id: Protocol.CSS.StyleSheetId): CSSStyleSheetHeader|null {
|
|
@@ -503,10 +502,10 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
503
502
|
if (!header) {
|
|
504
503
|
return Promise.resolve(null);
|
|
505
504
|
}
|
|
506
|
-
let promise = this.#
|
|
505
|
+
let promise = this.#originalStyleSheetText.get(header);
|
|
507
506
|
if (!promise) {
|
|
508
507
|
promise = this.getStyleSheetText(header.id);
|
|
509
|
-
this.#
|
|
508
|
+
this.#originalStyleSheetText.set(header, promise);
|
|
510
509
|
this.originalContentRequestedForTest(header);
|
|
511
510
|
}
|
|
512
511
|
return promise;
|
|
@@ -541,8 +540,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
541
540
|
}
|
|
542
541
|
styleSheetIds.add(styleSheetHeader.id);
|
|
543
542
|
}
|
|
544
|
-
this.#
|
|
545
|
-
styleSheetHeader, styleSheetHeader.sourceURL, styleSheetHeader.sourceMapURL);
|
|
543
|
+
this.#sourceMapManager.attachSourceMap(styleSheetHeader, styleSheetHeader.sourceURL, styleSheetHeader.sourceMapURL);
|
|
546
544
|
this.dispatchEventToListeners(Events.StyleSheetAdded, styleSheetHeader);
|
|
547
545
|
}
|
|
548
546
|
|
|
@@ -569,8 +567,8 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
569
567
|
}
|
|
570
568
|
}
|
|
571
569
|
}
|
|
572
|
-
this.#
|
|
573
|
-
this.#
|
|
570
|
+
this.#originalStyleSheetText.delete(header);
|
|
571
|
+
this.#sourceMapManager.detachSourceMap(header);
|
|
574
572
|
this.dispatchEventToListeners(Events.StyleSheetRemoved, header);
|
|
575
573
|
}
|
|
576
574
|
|
|
@@ -602,13 +600,13 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
602
600
|
const response = await this.agent.invoke_setStyleSheetText({styleSheetId: header.id, text: newText});
|
|
603
601
|
const sourceMapURL = response.sourceMapURL;
|
|
604
602
|
|
|
605
|
-
this.#
|
|
603
|
+
this.#sourceMapManager.detachSourceMap(header);
|
|
606
604
|
header.setSourceMapURL(sourceMapURL);
|
|
607
|
-
this.#
|
|
605
|
+
this.#sourceMapManager.attachSourceMap(header, header.sourceURL, header.sourceMapURL);
|
|
608
606
|
if (sourceMapURL === null) {
|
|
609
607
|
return 'Error in CSS.setStyleSheetText';
|
|
610
608
|
}
|
|
611
|
-
this.#
|
|
609
|
+
this.#domModel.markUndoableState(!majorChange);
|
|
612
610
|
this.fireStyleSheetChanged(styleSheetId);
|
|
613
611
|
return null;
|
|
614
612
|
}
|
|
@@ -622,22 +620,38 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
622
620
|
}
|
|
623
621
|
}
|
|
624
622
|
|
|
623
|
+
private async onMainFrameNavigated(event: Common.EventTarget.EventTargetEvent<ResourceTreeFrame>): Promise<void> {
|
|
624
|
+
// If the main frame was restored from the back-forward cache, the order of CDP
|
|
625
|
+
// is different from the regular navigations. In this case, events about CSS
|
|
626
|
+
// stylesheet has already been received and they are mixed with the previous page
|
|
627
|
+
// stylesheets. Therefore, we re-enable the CSS agent to get fresh events.
|
|
628
|
+
// For the regular navigatons, we can just clear the local data because events about
|
|
629
|
+
// stylesheets will arrive later.
|
|
630
|
+
if (event.data.backForwardCacheDetails.restoredFromCache) {
|
|
631
|
+
await this.suspendModel();
|
|
632
|
+
await this.resumeModel();
|
|
633
|
+
} else {
|
|
634
|
+
this.resetStyleSheets();
|
|
635
|
+
this.resetFontFaces();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
625
639
|
private resetStyleSheets(): void {
|
|
626
640
|
const headers = [...this.#styleSheetIdToHeader.values()];
|
|
627
641
|
this.#styleSheetIdsForURL.clear();
|
|
628
642
|
this.#styleSheetIdToHeader.clear();
|
|
629
643
|
for (const header of headers) {
|
|
630
|
-
this.#
|
|
644
|
+
this.#sourceMapManager.detachSourceMap(header);
|
|
631
645
|
this.dispatchEventToListeners(Events.StyleSheetRemoved, header);
|
|
632
646
|
}
|
|
633
647
|
}
|
|
634
648
|
|
|
635
649
|
private resetFontFaces(): void {
|
|
636
|
-
this.#
|
|
650
|
+
this.#fontFaces.clear();
|
|
637
651
|
}
|
|
638
652
|
|
|
639
653
|
async suspendModel(): Promise<void> {
|
|
640
|
-
this.#
|
|
654
|
+
this.#isEnabled = false;
|
|
641
655
|
await this.agent.invoke_disable();
|
|
642
656
|
this.resetStyleSheets();
|
|
643
657
|
this.resetFontFaces();
|
|
@@ -713,7 +727,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
713
727
|
if (this.#cssPropertyTracker) {
|
|
714
728
|
this.#cssPropertyTracker.dispatchEventToListeners(
|
|
715
729
|
CSSPropertyTrackerEvents.TrackedCSSPropertiesUpdated,
|
|
716
|
-
result.nodeIds.map(nodeId => this.#
|
|
730
|
+
result.nodeIds.map(nodeId => this.#domModel.nodeForId(nodeId)));
|
|
717
731
|
}
|
|
718
732
|
}
|
|
719
733
|
|
|
@@ -725,7 +739,7 @@ export class CSSModel extends SDKModel<EventTypes> {
|
|
|
725
739
|
dispose(): void {
|
|
726
740
|
this.disableCSSPropertyTracker();
|
|
727
741
|
super.dispose();
|
|
728
|
-
this.#
|
|
742
|
+
this.#sourceMapManager.dispose();
|
|
729
743
|
}
|
|
730
744
|
|
|
731
745
|
getAgent(): ProtocolProxyApi.CSSApi {
|
|
@@ -958,11 +958,24 @@ export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes,
|
|
|
958
958
|
(initiatorLink as HTMLElement).focus();
|
|
959
959
|
}
|
|
960
960
|
}
|
|
961
|
+
|
|
961
962
|
if (isEnterOrSpaceKey(event)) {
|
|
962
963
|
this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
|
|
963
964
|
event.consume(true);
|
|
964
965
|
}
|
|
965
966
|
});
|
|
967
|
+
this.dataGrid.element.addEventListener('keyup', event => {
|
|
968
|
+
if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
|
|
969
|
+
const request = (this.dataGrid.selectedNode as NetworkNode).request();
|
|
970
|
+
if (!request) {
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
|
|
975
|
+
SDK.NetworkManager.NetworkManager.replayRequest(request);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
});
|
|
966
979
|
this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
|
|
967
980
|
this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
|
|
968
981
|
return this.dataGrid;
|
package/package.json
CHANGED