devtools-tracing 1.0.1 → 1.1.1

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 (132) hide show
  1. package/generate.ts +32 -26
  2. package/index.ts +2 -1
  3. package/lib/extension-api/ExtensionAPI.d.ts +357 -0
  4. package/lib/front_end/models/bindings/CSSWorkspaceBinding.ts +318 -0
  5. package/lib/front_end/models/bindings/CompilerScriptMapping.ts +536 -0
  6. package/lib/front_end/models/bindings/ContentProviderBasedProject.ts +187 -0
  7. package/lib/front_end/models/bindings/DebuggerLanguagePlugins.ts +1197 -0
  8. package/lib/front_end/models/bindings/DebuggerWorkspaceBinding.ts +733 -0
  9. package/lib/front_end/models/bindings/DefaultScriptMapping.ts +141 -0
  10. package/lib/front_end/models/bindings/FileUtils.ts +228 -0
  11. package/lib/front_end/models/bindings/LiveLocation.ts +81 -0
  12. package/lib/front_end/models/bindings/NetworkProject.ts +157 -0
  13. package/lib/front_end/models/bindings/PresentationConsoleMessageHelper.ts +312 -0
  14. package/lib/front_end/models/bindings/ResourceMapping.ts +539 -0
  15. package/lib/front_end/models/bindings/ResourceScriptMapping.ts +491 -0
  16. package/lib/front_end/models/bindings/ResourceUtils.ts +103 -0
  17. package/lib/front_end/models/bindings/SASSSourceMapping.ts +222 -0
  18. package/lib/front_end/models/bindings/StylesSourceMapping.ts +316 -0
  19. package/lib/front_end/models/bindings/TempFile.ts +67 -0
  20. package/lib/front_end/models/bindings/bindings.ts +39 -0
  21. package/lib/front_end/models/source_map_scopes/NamesResolver.ts +765 -0
  22. package/lib/front_end/models/source_map_scopes/ScopeChainModel.ts +84 -0
  23. package/lib/front_end/models/source_map_scopes/source_map_scopes.ts +11 -0
  24. package/lib/front_end/models/stack_trace/StackTrace.ts +53 -0
  25. package/lib/front_end/models/stack_trace/StackTraceImpl.ts +85 -0
  26. package/lib/front_end/models/stack_trace/StackTraceModel.ts +128 -0
  27. package/lib/front_end/models/stack_trace/Trie.ts +163 -0
  28. package/lib/front_end/models/stack_trace/stack_trace.ts +9 -0
  29. package/lib/front_end/models/stack_trace/stack_trace_impl.ts +13 -0
  30. package/lib/front_end/models/trace_source_maps_resolver/SourceMapsResolver.ts +240 -0
  31. package/lib/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.ts +5 -0
  32. package/lib/front_end/models/workspace/FileManager.ts +97 -0
  33. package/lib/front_end/models/workspace/IgnoreListManager.ts +628 -0
  34. package/lib/front_end/models/workspace/SearchConfig.ts +149 -0
  35. package/lib/front_end/models/workspace/UISourceCode.ts +698 -0
  36. package/lib/front_end/models/workspace/WorkspaceImpl.ts +339 -0
  37. package/lib/front_end/models/workspace/workspace.ts +17 -0
  38. package/lib/front_end/panels/timeline/TimelineUIUtils.ts +1029 -0
  39. package/lib/front_end/panels/timeline/extensions/ExtensionUI.ts +49 -0
  40. package/lib/front_end/panels/timeline/extensions/extensions.ts +9 -0
  41. package/lib/front_end/third_party/codemirror.next/LICENSE +21 -0
  42. package/lib/front_end/third_party/codemirror.next/README.chromium +30 -0
  43. package/lib/front_end/third_party/codemirror.next/bundle-tsconfig.json +24 -0
  44. package/lib/front_end/third_party/codemirror.next/bundle.ts +135 -0
  45. package/lib/front_end/third_party/codemirror.next/chunk/angular.js +2 -0
  46. package/lib/front_end/third_party/codemirror.next/chunk/angular.js.map +1 -0
  47. package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js +2 -0
  48. package/lib/front_end/third_party/codemirror.next/chunk/codemirror.js.map +1 -0
  49. package/lib/front_end/third_party/codemirror.next/chunk/cpp.js +2 -0
  50. package/lib/front_end/third_party/codemirror.next/chunk/cpp.js.map +1 -0
  51. package/lib/front_end/third_party/codemirror.next/chunk/css.js +2 -0
  52. package/lib/front_end/third_party/codemirror.next/chunk/html.js +4 -0
  53. package/lib/front_end/third_party/codemirror.next/chunk/java.js +2 -0
  54. package/lib/front_end/third_party/codemirror.next/chunk/java.js.map +1 -0
  55. package/lib/front_end/third_party/codemirror.next/chunk/javascript.js +2 -0
  56. package/lib/front_end/third_party/codemirror.next/chunk/legacy.js +2 -0
  57. package/lib/front_end/third_party/codemirror.next/chunk/legacy.js.map +1 -0
  58. package/lib/front_end/third_party/codemirror.next/chunk/less.js +2 -0
  59. package/lib/front_end/third_party/codemirror.next/chunk/less.js.map +1 -0
  60. package/lib/front_end/third_party/codemirror.next/chunk/markdown.js +2 -0
  61. package/lib/front_end/third_party/codemirror.next/chunk/markdown.js.map +1 -0
  62. package/lib/front_end/third_party/codemirror.next/chunk/php.js +2 -0
  63. package/lib/front_end/third_party/codemirror.next/chunk/php.js.map +1 -0
  64. package/lib/front_end/third_party/codemirror.next/chunk/python.js +2 -0
  65. package/lib/front_end/third_party/codemirror.next/chunk/python.js.map +1 -0
  66. package/lib/front_end/third_party/codemirror.next/chunk/sass.js +2 -0
  67. package/lib/front_end/third_party/codemirror.next/chunk/sass.js.map +1 -0
  68. package/lib/front_end/third_party/codemirror.next/chunk/svelte.js +2 -0
  69. package/lib/front_end/third_party/codemirror.next/chunk/svelte.js.map +1 -0
  70. package/lib/front_end/third_party/codemirror.next/chunk/vue.js +2 -0
  71. package/lib/front_end/third_party/codemirror.next/chunk/vue.js.map +1 -0
  72. package/lib/front_end/third_party/codemirror.next/chunk/wast.js +2 -0
  73. package/lib/front_end/third_party/codemirror.next/chunk/wast.js.map +1 -0
  74. package/lib/front_end/third_party/codemirror.next/chunk/xml.js +2 -0
  75. package/lib/front_end/third_party/codemirror.next/chunk/xml.js.map +1 -0
  76. package/lib/front_end/third_party/codemirror.next/codemirror.next.d.ts +8057 -0
  77. package/lib/front_end/third_party/codemirror.next/codemirror.next.js +2 -0
  78. package/lib/front_end/third_party/codemirror.next/codemirror.next.js.map +1 -0
  79. package/lib/front_end/third_party/codemirror.next/package.json +43 -0
  80. package/lib/front_end/third_party/codemirror.next/rebuild.sh +6 -0
  81. package/lib/front_end/third_party/codemirror.next/rollup.config.mjs +49 -0
  82. package/lib/front_end/third_party/source-map-scopes-codec/LICENSE +26 -0
  83. package/lib/front_end/third_party/source-map-scopes-codec/README.chromium +31 -0
  84. package/lib/front_end/third_party/source-map-scopes-codec/package/CONTRIBUTING.md +33 -0
  85. package/lib/front_end/third_party/source-map-scopes-codec/package/LICENSE +26 -0
  86. package/lib/front_end/third_party/source-map-scopes-codec/package/README.md +64 -0
  87. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts +62 -0
  88. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/builder.d.ts.map +1 -0
  89. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts +37 -0
  90. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/builder/safe_builder.d.ts.map +1 -0
  91. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts +29 -0
  92. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/decode/decode.d.ts.map +1 -0
  93. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts +8 -0
  94. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/encode/encode.d.ts.map +1 -0
  95. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts +6 -0
  96. package/lib/front_end/third_party/source-map-scopes-codec/package/_dist/src/mod.d.ts.map +1 -0
  97. package/lib/front_end/third_party/source-map-scopes-codec/package/deno.json +21 -0
  98. package/lib/front_end/third_party/source-map-scopes-codec/package/package.json +14 -0
  99. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js +196 -0
  100. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.js.map +1 -0
  101. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/builder.ts +262 -0
  102. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js +235 -0
  103. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.js.map +1 -0
  104. package/lib/front_end/third_party/source-map-scopes-codec/package/src/builder/safe_builder.ts +359 -0
  105. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js +39 -0
  106. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.js.map +1 -0
  107. package/lib/front_end/third_party/source-map-scopes-codec/package/src/codec.ts +53 -0
  108. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js +438 -0
  109. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.js.map +1 -0
  110. package/lib/front_end/third_party/source-map-scopes-codec/package/src/decode/decode.ts +539 -0
  111. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js +23 -0
  112. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.js.map +1 -0
  113. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encode.ts +35 -0
  114. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js +257 -0
  115. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.js.map +1 -0
  116. package/lib/front_end/third_party/source-map-scopes-codec/package/src/encode/encoder.ts +348 -0
  117. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js +8 -0
  118. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.js.map +1 -0
  119. package/lib/front_end/third_party/source-map-scopes-codec/package/src/mod.ts +20 -0
  120. package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes-tsconfig.json +8 -0
  121. package/lib/front_end/third_party/source-map-scopes-codec/package/src/scopes.d.ts +184 -0
  122. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js +9 -0
  123. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.js.map +1 -0
  124. package/lib/front_end/third_party/source-map-scopes-codec/package/src/util.ts +12 -0
  125. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js +82 -0
  126. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.js.map +1 -0
  127. package/lib/front_end/third_party/source-map-scopes-codec/package/src/vlq.ts +99 -0
  128. package/lib/front_end/third_party/source-map-scopes-codec/source-map-scopes-codec.ts +5 -0
  129. package/lib/front_end/ui/legacy/theme_support/ThemeSupport.ts +222 -0
  130. package/lib/front_end/ui/legacy/theme_support/theme_support.ts +5 -0
  131. package/package.json +5 -5
  132. package/patches/chrome-devtools-frontend+1.0.1533544.patch +1549 -20
@@ -0,0 +1,628 @@
1
+ // Copyright 2014 The Chromium Authors
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 * as Common from '../../core/common/common.js';
6
+ import * as i18n from '../../core/i18n/i18n.js';
7
+ import * as Platform from '../../core/platform/platform.js';
8
+ import * as SDK from '../../core/sdk/sdk.js';
9
+
10
+ import type {UISourceCode} from './UISourceCode.js';
11
+ import {projectTypes} from './WorkspaceImpl.js';
12
+
13
+ const UIStrings = {
14
+ /**
15
+ * @description Text to stop preventing the debugger from stepping into library code
16
+ */
17
+ removeFromIgnoreList: 'Remove from ignore list',
18
+ /**
19
+ * @description Text for scripts that should not be stepped into when debugging
20
+ */
21
+ addScriptToIgnoreList: 'Add script to ignore list',
22
+ /**
23
+ * @description Text for directories whose scripts should not be stepped into when debugging
24
+ */
25
+ addDirectoryToIgnoreList: 'Add directory to ignore list',
26
+ /**
27
+ * @description A context menu item in the Call Stack Sidebar Pane of the Sources panel
28
+ */
29
+ addAllContentScriptsToIgnoreList: 'Add all extension scripts to ignore list',
30
+ /**
31
+ * @description A context menu item in the Call Stack Sidebar Pane of the Sources panel
32
+ */
33
+ addAllThirdPartyScriptsToIgnoreList: 'Add all third-party scripts to ignore list',
34
+ /**
35
+ * @description A context menu item in the Call Stack Sidebar Pane of the Sources panel
36
+ */
37
+ addAllAnonymousScriptsToIgnoreList: 'Add all anonymous scripts to ignore list',
38
+ } as const;
39
+
40
+ const str_ = i18n.i18n.registerUIStrings('models/workspace/IgnoreListManager.ts', UIStrings);
41
+ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
42
+
43
+ let ignoreListManagerInstance: IgnoreListManager|undefined;
44
+
45
+ export interface IgnoreListGeneralRules {
46
+ isContentScript?: boolean;
47
+ isKnownThirdParty?: boolean;
48
+ isCurrentlyIgnoreListed?: boolean;
49
+ }
50
+
51
+ export class IgnoreListManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes> implements
52
+ SDK.TargetManager.SDKModelObserver<SDK.DebuggerModel.DebuggerModel> {
53
+ readonly #listeners: Set<() => void>;
54
+ readonly #isIgnoreListedURLCache: Map<string, boolean>;
55
+ readonly #contentScriptExecutionContexts: Set<string>;
56
+
57
+ private constructor() {
58
+ super();
59
+
60
+ SDK.TargetManager.TargetManager.instance().addModelListener(
61
+ SDK.DebuggerModel.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared,
62
+ this.clearCacheIfNeeded.bind(this), this);
63
+ SDK.TargetManager.TargetManager.instance().addModelListener(
64
+ SDK.RuntimeModel.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this.onExecutionContextCreated,
65
+ this, {scoped: true});
66
+ SDK.TargetManager.TargetManager.instance().addModelListener(
67
+ SDK.RuntimeModel.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed,
68
+ this.onExecutionContextDestroyed, this, {scoped: true});
69
+ Common.Settings.Settings.instance()
70
+ .moduleSetting('skip-stack-frames-pattern')
71
+ .addChangeListener(this.patternChanged.bind(this));
72
+ Common.Settings.Settings.instance()
73
+ .moduleSetting('skip-content-scripts')
74
+ .addChangeListener(this.patternChanged.bind(this));
75
+ Common.Settings.Settings.instance()
76
+ .moduleSetting('automatically-ignore-list-known-third-party-scripts')
77
+ .addChangeListener(this.patternChanged.bind(this));
78
+ Common.Settings.Settings.instance()
79
+ .moduleSetting('enable-ignore-listing')
80
+ .addChangeListener(this.patternChanged.bind(this));
81
+ Common.Settings.Settings.instance()
82
+ .moduleSetting('skip-anonymous-scripts')
83
+ .addChangeListener(this.patternChanged.bind(this));
84
+
85
+ this.#listeners = new Set();
86
+ this.#isIgnoreListedURLCache = new Map();
87
+ this.#contentScriptExecutionContexts = new Set();
88
+
89
+ SDK.TargetManager.TargetManager.instance().observeModels(SDK.DebuggerModel.DebuggerModel, this);
90
+ }
91
+
92
+ static instance(opts: {
93
+ forceNew: boolean|null,
94
+ } = {forceNew: null}): IgnoreListManager {
95
+ const {forceNew} = opts;
96
+ if (!ignoreListManagerInstance || forceNew) {
97
+ ignoreListManagerInstance = new IgnoreListManager();
98
+ }
99
+
100
+ return ignoreListManagerInstance;
101
+ }
102
+
103
+ static removeInstance(): void {
104
+ ignoreListManagerInstance = undefined;
105
+ }
106
+
107
+ addChangeListener(listener: () => void): void {
108
+ this.#listeners.add(listener);
109
+ }
110
+
111
+ removeChangeListener(listener: () => void): void {
112
+ this.#listeners.delete(listener);
113
+ }
114
+
115
+ modelAdded(debuggerModel: SDK.DebuggerModel.DebuggerModel): void {
116
+ void this.setIgnoreListPatterns(debuggerModel);
117
+ const sourceMapManager = debuggerModel.sourceMapManager();
118
+ sourceMapManager.addEventListener(SDK.SourceMapManager.Events.SourceMapAttached, this.sourceMapAttached, this);
119
+ sourceMapManager.addEventListener(SDK.SourceMapManager.Events.SourceMapDetached, this.sourceMapDetached, this);
120
+ }
121
+
122
+ modelRemoved(debuggerModel: SDK.DebuggerModel.DebuggerModel): void {
123
+ this.clearCacheIfNeeded();
124
+ const sourceMapManager = debuggerModel.sourceMapManager();
125
+ sourceMapManager.removeEventListener(SDK.SourceMapManager.Events.SourceMapAttached, this.sourceMapAttached, this);
126
+ sourceMapManager.removeEventListener(SDK.SourceMapManager.Events.SourceMapDetached, this.sourceMapDetached, this);
127
+ }
128
+
129
+ private isContentScript(executionContext: SDK.RuntimeModel.ExecutionContext): boolean {
130
+ return !executionContext.isDefault;
131
+ }
132
+
133
+ private onExecutionContextCreated(event: Common.EventTarget.EventTargetEvent<SDK.RuntimeModel.ExecutionContext>):
134
+ void {
135
+ if (this.isContentScript(event.data)) {
136
+ this.#contentScriptExecutionContexts.add(event.data.uniqueId);
137
+ if (this.skipContentScripts) {
138
+ for (const debuggerModel of SDK.TargetManager.TargetManager.instance().models(
139
+ SDK.DebuggerModel.DebuggerModel)) {
140
+ void this.updateIgnoredExecutionContexts(debuggerModel);
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ private onExecutionContextDestroyed(event: Common.EventTarget.EventTargetEvent<SDK.RuntimeModel.ExecutionContext>):
147
+ void {
148
+ if (this.isContentScript(event.data)) {
149
+ this.#contentScriptExecutionContexts.delete(event.data.uniqueId);
150
+ if (this.skipContentScripts) {
151
+ for (const debuggerModel of SDK.TargetManager.TargetManager.instance().models(
152
+ SDK.DebuggerModel.DebuggerModel)) {
153
+ void this.updateIgnoredExecutionContexts(debuggerModel);
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ private clearCacheIfNeeded(): void {
160
+ if (this.#isIgnoreListedURLCache.size > 1024) {
161
+ this.#isIgnoreListedURLCache.clear();
162
+ }
163
+ }
164
+
165
+ private getSkipStackFramesPatternSetting(): Common.Settings.RegExpSetting {
166
+ return Common.Settings.Settings.instance().moduleSetting('skip-stack-frames-pattern') as
167
+ Common.Settings.RegExpSetting;
168
+ }
169
+
170
+ private setIgnoreListPatterns(debuggerModel: SDK.DebuggerModel.DebuggerModel): Promise<boolean> {
171
+ const regexPatterns = this.enableIgnoreListing ? this.getSkipStackFramesPatternSetting().getAsArray() : [];
172
+ const patterns = ([] as string[]);
173
+ for (const item of regexPatterns) {
174
+ if (!item.disabled && item.pattern) {
175
+ patterns.push(item.pattern);
176
+ }
177
+ }
178
+ return debuggerModel.setBlackboxPatterns(patterns, this.skipAnonymousScripts);
179
+ }
180
+
181
+ private updateIgnoredExecutionContexts(debuggerModel: SDK.DebuggerModel.DebuggerModel): Promise<boolean> {
182
+ return debuggerModel.setBlackboxExecutionContexts(
183
+ this.skipContentScripts ? Array.from(this.#contentScriptExecutionContexts) : []);
184
+ }
185
+
186
+ private getGeneralRulesForUISourceCode(uiSourceCode: UISourceCode): IgnoreListGeneralRules {
187
+ const projectType = uiSourceCode.project().type();
188
+ const isContentScript = projectType === projectTypes.ContentScripts;
189
+ const isKnownThirdParty = uiSourceCode.isKnownThirdParty();
190
+ return {isContentScript, isKnownThirdParty};
191
+ }
192
+
193
+ isUserOrSourceMapIgnoreListedUISourceCode(uiSourceCode: UISourceCode): boolean {
194
+ if (uiSourceCode.isUnconditionallyIgnoreListed()) {
195
+ return true;
196
+ }
197
+ const url = this.uiSourceCodeURL(uiSourceCode);
198
+ return this.isUserIgnoreListedURL(url, this.getGeneralRulesForUISourceCode(uiSourceCode));
199
+ }
200
+
201
+ isUserIgnoreListedURL(url: Platform.DevToolsPath.UrlString|null, options?: IgnoreListGeneralRules): boolean {
202
+ if (!this.enableIgnoreListing) {
203
+ return false;
204
+ }
205
+ if (options?.isContentScript && this.skipContentScripts) {
206
+ return true;
207
+ }
208
+ if (options?.isKnownThirdParty && this.automaticallyIgnoreListKnownThirdPartyScripts) {
209
+ return true;
210
+ }
211
+ if (!url) {
212
+ return this.skipAnonymousScripts;
213
+ }
214
+ if (this.#isIgnoreListedURLCache.has(url)) {
215
+ return Boolean(this.#isIgnoreListedURLCache.get(url));
216
+ }
217
+
218
+ const isIgnoreListed = this.getFirstMatchedRegex(url) !== null;
219
+ this.#isIgnoreListedURLCache.set(url, isIgnoreListed);
220
+ return isIgnoreListed;
221
+ }
222
+
223
+ getFirstMatchedRegex(url: Platform.DevToolsPath.UrlString): RegExp|null {
224
+ if (!url) {
225
+ return null;
226
+ }
227
+ const regexPatterns = this.getSkipStackFramesPatternSetting().getAsArray();
228
+ const regexValue = this.urlToRegExpString(url);
229
+ if (!regexValue) {
230
+ return null;
231
+ }
232
+
233
+ for (let i = 0; i < regexPatterns.length; ++i) {
234
+ const item = regexPatterns[i];
235
+ if (item.disabled || item.disabledForUrl === url) {
236
+ continue;
237
+ }
238
+ const regex = new RegExp(item.pattern);
239
+ if (regex.test(url)) {
240
+ return regex;
241
+ }
242
+ }
243
+ return null;
244
+ }
245
+
246
+ private sourceMapAttached(
247
+ event: Common.EventTarget.EventTargetEvent<{client: SDK.Script.Script, sourceMap: SDK.SourceMap.SourceMap}>):
248
+ void {
249
+ const script = event.data.client;
250
+ const sourceMap = event.data.sourceMap;
251
+ void this.updateScriptRanges(script, sourceMap);
252
+ }
253
+
254
+ private sourceMapDetached(
255
+ event: Common.EventTarget.EventTargetEvent<{client: SDK.Script.Script, sourceMap: SDK.SourceMap.SourceMap}>):
256
+ void {
257
+ const script = event.data.client;
258
+ void this.updateScriptRanges(script, undefined);
259
+ }
260
+
261
+ private async updateScriptRanges(script: SDK.Script.Script, sourceMap: SDK.SourceMap.SourceMap|undefined):
262
+ Promise<void> {
263
+ let hasIgnoreListedMappings = false;
264
+ if (!IgnoreListManager.instance().isUserIgnoreListedURL(
265
+ script.sourceURL, {isContentScript: script.isContentScript()})) {
266
+ hasIgnoreListedMappings =
267
+ sourceMap?.sourceURLs().some(
268
+ url => this.isUserIgnoreListedURL(url, {isKnownThirdParty: sourceMap.hasIgnoreListHint(url)})) ??
269
+ false;
270
+ }
271
+ if (!hasIgnoreListedMappings) {
272
+ if (scriptToRange.get(script) && await script.setBlackboxedRanges([])) {
273
+ scriptToRange.delete(script);
274
+ }
275
+ this.dispatchEventToListeners(Events.IGNORED_SCRIPT_RANGES_UPDATED, script);
276
+ return;
277
+ }
278
+
279
+ if (!sourceMap) {
280
+ return;
281
+ }
282
+
283
+ const newRanges =
284
+ sourceMap
285
+ .findRanges(
286
+ srcURL => this.isUserIgnoreListedURL(srcURL, {isKnownThirdParty: sourceMap.hasIgnoreListHint(srcURL)}),
287
+ {isStartMatching: true})
288
+ .flatMap(range => [range.start, range.end]);
289
+
290
+ const oldRanges = scriptToRange.get(script) || [];
291
+ if (!isEqual(oldRanges, newRanges) && await script.setBlackboxedRanges(newRanges)) {
292
+ scriptToRange.set(script, newRanges);
293
+ }
294
+ this.dispatchEventToListeners(Events.IGNORED_SCRIPT_RANGES_UPDATED, script);
295
+
296
+ function isEqual(rangesA: SourceRange[], rangesB: SourceRange[]): boolean {
297
+ if (rangesA.length !== rangesB.length) {
298
+ return false;
299
+ }
300
+ for (let i = 0; i < rangesA.length; ++i) {
301
+ if (rangesA[i].lineNumber !== rangesB[i].lineNumber || rangesA[i].columnNumber !== rangesB[i].columnNumber) {
302
+ return false;
303
+ }
304
+ }
305
+ return true;
306
+ }
307
+ }
308
+
309
+ private uiSourceCodeURL(uiSourceCode: UISourceCode): Platform.DevToolsPath.UrlString|null {
310
+ return uiSourceCode.project().type() === projectTypes.Debugger ? null : uiSourceCode.url();
311
+ }
312
+
313
+ canIgnoreListUISourceCode(uiSourceCode: UISourceCode): boolean {
314
+ const url = this.uiSourceCodeURL(uiSourceCode);
315
+ return url ? Boolean(this.urlToRegExpString(url)) : false;
316
+ }
317
+
318
+ ignoreListUISourceCode(uiSourceCode: UISourceCode): void {
319
+ const url = this.uiSourceCodeURL(uiSourceCode);
320
+ if (url) {
321
+ this.ignoreListURL(url);
322
+ }
323
+ }
324
+
325
+ unIgnoreListUISourceCode(uiSourceCode: UISourceCode): void {
326
+ this.unIgnoreListURL(this.uiSourceCodeURL(uiSourceCode), this.getGeneralRulesForUISourceCode(uiSourceCode));
327
+ }
328
+
329
+ get enableIgnoreListing(): boolean {
330
+ return Common.Settings.Settings.instance().moduleSetting('enable-ignore-listing').get();
331
+ }
332
+
333
+ set enableIgnoreListing(value: boolean) {
334
+ Common.Settings.Settings.instance().moduleSetting('enable-ignore-listing').set(value);
335
+ }
336
+
337
+ get skipContentScripts(): boolean {
338
+ return this.enableIgnoreListing && Common.Settings.Settings.instance().moduleSetting('skip-content-scripts').get();
339
+ }
340
+
341
+ get skipAnonymousScripts(): boolean {
342
+ return this.enableIgnoreListing &&
343
+ Common.Settings.Settings.instance().moduleSetting('skip-anonymous-scripts').get();
344
+ }
345
+
346
+ get automaticallyIgnoreListKnownThirdPartyScripts(): boolean {
347
+ return this.enableIgnoreListing &&
348
+ Common.Settings.Settings.instance().moduleSetting('automatically-ignore-list-known-third-party-scripts').get();
349
+ }
350
+
351
+ ignoreListContentScripts(): void {
352
+ if (!this.enableIgnoreListing) {
353
+ this.enableIgnoreListing = true;
354
+ }
355
+ Common.Settings.Settings.instance().moduleSetting('skip-content-scripts').set(true);
356
+ }
357
+
358
+ unIgnoreListContentScripts(): void {
359
+ Common.Settings.Settings.instance().moduleSetting('skip-content-scripts').set(false);
360
+ }
361
+
362
+ ignoreListAnonymousScripts(): void {
363
+ if (!this.enableIgnoreListing) {
364
+ this.enableIgnoreListing = true;
365
+ }
366
+ Common.Settings.Settings.instance().moduleSetting('skip-anonymous-scripts').set(true);
367
+ }
368
+
369
+ unIgnoreListAnonymousScripts(): void {
370
+ Common.Settings.Settings.instance().moduleSetting('skip-anonymous-scripts').set(false);
371
+ }
372
+
373
+ ignoreListThirdParty(): void {
374
+ if (!this.enableIgnoreListing) {
375
+ this.enableIgnoreListing = true;
376
+ }
377
+ Common.Settings.Settings.instance().moduleSetting('automatically-ignore-list-known-third-party-scripts').set(true);
378
+ }
379
+
380
+ unIgnoreListThirdParty(): void {
381
+ Common.Settings.Settings.instance().moduleSetting('automatically-ignore-list-known-third-party-scripts').set(false);
382
+ }
383
+
384
+ ignoreListURL(url: Platform.DevToolsPath.UrlString): void {
385
+ const regexValue = this.urlToRegExpString(url);
386
+ if (!regexValue) {
387
+ return;
388
+ }
389
+ this.addRegexToIgnoreList(regexValue, url);
390
+ }
391
+
392
+ addRegexToIgnoreList(regexValue: string, disabledForUrl?: Platform.DevToolsPath.UrlString): void {
393
+ const regexPatterns = this.getSkipStackFramesPatternSetting().getAsArray();
394
+
395
+ let found = false;
396
+ for (let i = 0; i < regexPatterns.length; ++i) {
397
+ const item = regexPatterns[i];
398
+ if (item.pattern === regexValue || (disabledForUrl && item.disabledForUrl === disabledForUrl)) {
399
+ item.disabled = false;
400
+ item.disabledForUrl = undefined;
401
+ found = true;
402
+ }
403
+ }
404
+ if (!found) {
405
+ regexPatterns.push({pattern: regexValue, disabled: false});
406
+ }
407
+ if (!this.enableIgnoreListing) {
408
+ this.enableIgnoreListing = true;
409
+ }
410
+ this.getSkipStackFramesPatternSetting().setAsArray(regexPatterns);
411
+ }
412
+
413
+ unIgnoreListURL(url: Platform.DevToolsPath.UrlString|null, options?: IgnoreListGeneralRules): void {
414
+ if (options?.isContentScript) {
415
+ this.unIgnoreListContentScripts();
416
+ }
417
+
418
+ if (options?.isKnownThirdParty) {
419
+ this.unIgnoreListThirdParty();
420
+ }
421
+
422
+ if (!url) {
423
+ this.unIgnoreListAnonymousScripts();
424
+ return;
425
+ }
426
+
427
+ let regexPatterns = this.getSkipStackFramesPatternSetting().getAsArray();
428
+ const regexValue = IgnoreListManager.instance().urlToRegExpString(url);
429
+ if (!regexValue) {
430
+ return;
431
+ }
432
+
433
+ regexPatterns = regexPatterns.filter(function(item) {
434
+ return item.pattern !== regexValue;
435
+ });
436
+ for (let i = 0; i < regexPatterns.length; ++i) {
437
+ const item = regexPatterns[i];
438
+ if (item.disabled) {
439
+ continue;
440
+ }
441
+ try {
442
+ const regex = new RegExp(item.pattern);
443
+ if (regex.test(url)) {
444
+ item.disabled = true;
445
+ item.disabledForUrl = url;
446
+ }
447
+ } catch {
448
+ }
449
+ }
450
+ this.getSkipStackFramesPatternSetting().setAsArray(regexPatterns);
451
+ }
452
+
453
+ private removeIgnoreListPattern(regexValue: string): void {
454
+ let regexPatterns = this.getSkipStackFramesPatternSetting().getAsArray();
455
+ regexPatterns = regexPatterns.filter(function(item) {
456
+ return item.pattern !== regexValue;
457
+ });
458
+ this.getSkipStackFramesPatternSetting().setAsArray(regexPatterns);
459
+ }
460
+
461
+ private ignoreListHasPattern(regexValue: string, enabledOnly: boolean): boolean {
462
+ const regexPatterns = this.getSkipStackFramesPatternSetting().getAsArray();
463
+ return regexPatterns.some(item => !(enabledOnly && item.disabled) && item.pattern === regexValue);
464
+ }
465
+
466
+ private async patternChanged(): Promise<void> {
467
+ this.#isIgnoreListedURLCache.clear();
468
+
469
+ const promises: Array<Promise<unknown>> = [];
470
+ for (const debuggerModel of SDK.TargetManager.TargetManager.instance().models(SDK.DebuggerModel.DebuggerModel)) {
471
+ promises.push(this.setIgnoreListPatterns(debuggerModel));
472
+ const sourceMapManager = debuggerModel.sourceMapManager();
473
+ for (const script of debuggerModel.scripts()) {
474
+ promises.push(this.updateScriptRanges(script, sourceMapManager.sourceMapForClient(script)));
475
+ }
476
+ promises.push(this.updateIgnoredExecutionContexts(debuggerModel));
477
+ }
478
+ await Promise.all(promises);
479
+ const listeners = Array.from(this.#listeners);
480
+ for (const listener of listeners) {
481
+ listener();
482
+ }
483
+ this.patternChangeFinishedForTests();
484
+ }
485
+
486
+ private patternChangeFinishedForTests(): void {
487
+ // This method is sniffed in tests.
488
+ }
489
+
490
+ private urlToRegExpString(url: Platform.DevToolsPath.UrlString): string {
491
+ const parsedURL = new Common.ParsedURL.ParsedURL(url);
492
+ if (parsedURL.isAboutBlank() || parsedURL.isDataURL()) {
493
+ return '';
494
+ }
495
+ if (!parsedURL.isValid) {
496
+ return '^' + Platform.StringUtilities.escapeForRegExp(url) + '$';
497
+ }
498
+ let name: string = parsedURL.lastPathComponent;
499
+ if (name) {
500
+ name = '/' + name;
501
+ } else if (parsedURL.folderPathComponents) {
502
+ name = parsedURL.folderPathComponents + '/';
503
+ }
504
+ if (!name) {
505
+ name = parsedURL.host;
506
+ }
507
+ if (!name) {
508
+ return '';
509
+ }
510
+ const scheme = parsedURL.scheme;
511
+ let prefix = '';
512
+ if (scheme && scheme !== 'http' && scheme !== 'https') {
513
+ prefix = '^' + scheme + '://';
514
+ if (scheme === 'chrome-extension') {
515
+ prefix += parsedURL.host + '\\b';
516
+ }
517
+ prefix += '.*';
518
+ }
519
+ return prefix + Platform.StringUtilities.escapeForRegExp(name) + (url.endsWith(name) ? '$' : '\\b');
520
+ }
521
+
522
+ getIgnoreListURLContextMenuItems(uiSourceCode: UISourceCode):
523
+ Array<{text: string, callback: () => void, jslogContext: string}> {
524
+ if (uiSourceCode.project().type() === projectTypes.FileSystem) {
525
+ return [];
526
+ }
527
+
528
+ const menuItems: Array<{text: string, callback: () => void, jslogContext: string}> = [];
529
+ const canIgnoreList = this.canIgnoreListUISourceCode(uiSourceCode);
530
+ const isIgnoreListed = this.isUserOrSourceMapIgnoreListedUISourceCode(uiSourceCode);
531
+ const isAnonymous = !this.uiSourceCodeURL(uiSourceCode);
532
+ const {isContentScript, isKnownThirdParty} = this.getGeneralRulesForUISourceCode(uiSourceCode);
533
+
534
+ if (isIgnoreListed) {
535
+ if (canIgnoreList || isContentScript || isKnownThirdParty || isAnonymous) {
536
+ menuItems.push({
537
+ text: i18nString(UIStrings.removeFromIgnoreList),
538
+ callback: this.unIgnoreListUISourceCode.bind(this, uiSourceCode),
539
+ jslogContext: 'remove-script-from-ignorelist',
540
+ });
541
+ }
542
+ } else {
543
+ if (canIgnoreList) {
544
+ menuItems.push({
545
+ text: i18nString(UIStrings.addScriptToIgnoreList),
546
+ callback: this.ignoreListUISourceCode.bind(this, uiSourceCode),
547
+ jslogContext: 'add-script-to-ignorelist',
548
+ });
549
+ } else if (isAnonymous) {
550
+ menuItems.push({
551
+ text: i18nString(UIStrings.addAllAnonymousScriptsToIgnoreList),
552
+ callback: this.ignoreListAnonymousScripts.bind(this),
553
+ jslogContext: 'add-anonymous-scripts-to-ignorelist',
554
+ });
555
+ }
556
+ menuItems.push(...this.getIgnoreListGeneralContextMenuItems({isContentScript, isKnownThirdParty}));
557
+ }
558
+
559
+ return menuItems;
560
+ }
561
+
562
+ private getIgnoreListGeneralContextMenuItems(options?: IgnoreListGeneralRules):
563
+ Array<{text: string, callback: () => void, jslogContext: string}> {
564
+ const menuItems: Array<{text: string, callback: () => void, jslogContext: string}> = [];
565
+ if (options?.isContentScript) {
566
+ menuItems.push({
567
+ text: i18nString(UIStrings.addAllContentScriptsToIgnoreList),
568
+ callback: this.ignoreListContentScripts.bind(this),
569
+ jslogContext: 'add-content-scripts-to-ignorelist',
570
+ });
571
+ }
572
+ if (options?.isKnownThirdParty) {
573
+ menuItems.push({
574
+ text: i18nString(UIStrings.addAllThirdPartyScriptsToIgnoreList),
575
+ callback: this.ignoreListThirdParty.bind(this),
576
+ jslogContext: 'add-3p-scripts-to-ignorelist',
577
+ });
578
+ }
579
+ return menuItems;
580
+ }
581
+
582
+ getIgnoreListFolderContextMenuItems(url: Platform.DevToolsPath.UrlString, options?: IgnoreListGeneralRules):
583
+ Array<{text: string, callback: () => void, jslogContext: string}> {
584
+ const menuItems: Array<{text: string, callback: () => void, jslogContext: string}> = [];
585
+
586
+ const regexValue = '^' + Platform.StringUtilities.escapeForRegExp(url) + '/';
587
+ if (this.ignoreListHasPattern(regexValue, true)) {
588
+ menuItems.push({
589
+ text: i18nString(UIStrings.removeFromIgnoreList),
590
+ callback: this.removeIgnoreListPattern.bind(this, regexValue),
591
+ jslogContext: 'remove-from-ignore-list',
592
+ });
593
+ } else if (this.isUserIgnoreListedURL(url, options)) {
594
+ // This specific url isn't on the ignore list, but there are rules that match it.
595
+ menuItems.push({
596
+ text: i18nString(UIStrings.removeFromIgnoreList),
597
+ callback: this.unIgnoreListURL.bind(this, url, options),
598
+ jslogContext: 'remove-from-ignore-list',
599
+ });
600
+ } else if (!options?.isCurrentlyIgnoreListed) {
601
+ // Provide options to add to ignore list, unless folder currently displays
602
+ // as entirely ignored.
603
+ menuItems.push({
604
+ text: i18nString(UIStrings.addDirectoryToIgnoreList),
605
+ callback: this.addRegexToIgnoreList.bind(this, regexValue),
606
+ jslogContext: 'add-directory-to-ignore-list',
607
+ });
608
+ menuItems.push(...this.getIgnoreListGeneralContextMenuItems(options));
609
+ }
610
+
611
+ return menuItems;
612
+ }
613
+ }
614
+
615
+ export interface SourceRange {
616
+ lineNumber: number;
617
+ columnNumber: number;
618
+ }
619
+
620
+ const scriptToRange = new WeakMap<SDK.Script.Script, SourceRange[]>();
621
+
622
+ export const enum Events {
623
+ IGNORED_SCRIPT_RANGES_UPDATED = 'IGNORED_SCRIPT_RANGES_UPDATED',
624
+ }
625
+
626
+ export interface EventTypes {
627
+ [Events.IGNORED_SCRIPT_RANGES_UPDATED]: SDK.Script.Script;
628
+ }