MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / PageEventSubscriber

Class PageEventSubscriber

src/PageCollector.ts:244–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244class PageEventSubscriber {
245 #issueManager = new FakeIssuesManager();
246 #issueAggregator = new DevTools.IssueAggregator(this.#issueManager);
247 #seenKeys = new Set<string>();
248 #seenIssues = new Set<DevTools.AggregatedIssue>();
249 #page: Page;
250 #session: CDPSession;
251 #targetId: string;
252
253 constructor(page: Page) {
254 this.#page = page;
255 // @ts-expect-error use existing CDP client (internal Puppeteer API).
256 this.#session = this.#page._client() as CDPSession;
257 // @ts-expect-error use internal Puppeteer API to get target ID
258 this.#targetId = this.#session.target()._targetId;
259 }
260
261 #resetIssueAggregator() {
262 this.#issueManager = new FakeIssuesManager();
263 if (this.#issueAggregator) {
264 this.#issueAggregator.removeEventListener(
265 DevTools.IssueAggregatorEvents.AGGREGATED_ISSUE_UPDATED,
266 this.#onAggregatedIssue,
267 );
268 }
269 this.#issueAggregator = new DevTools.IssueAggregator(this.#issueManager);
270 this.#issueAggregator.addEventListener(
271 DevTools.IssueAggregatorEvents.AGGREGATED_ISSUE_UPDATED,
272 this.#onAggregatedIssue,
273 );
274 }
275
276 async subscribe() {
277 this.#resetIssueAggregator();
278 this.#page.on('framenavigated', this.#onFrameNavigated);
279 this.#page.on('issue', this.#onIssueAdded);
280 this.#session.on('Runtime.exceptionThrown', this.#onExceptionThrown);
281 }
282
283 unsubscribe() {
284 this.#seenKeys.clear();
285 this.#seenIssues.clear();
286 this.#page.off('framenavigated', this.#onFrameNavigated);
287 this.#page.off('issue', this.#onIssueAdded);
288 this.#session.off('Runtime.exceptionThrown', this.#onExceptionThrown);
289 if (this.#issueAggregator) {
290 this.#issueAggregator.removeEventListener(
291 DevTools.IssueAggregatorEvents.AGGREGATED_ISSUE_UPDATED,
292 this.#onAggregatedIssue,
293 );
294 }
295 }
296
297 #onAggregatedIssue = (
298 event: DevTools.Common.EventTarget.EventTargetEvent<DevTools.AggregatedIssue>,
299 ) => {
300 if (this.#seenIssues.has(event.data)) {
301 return;

Callers

nothing calls this directly

Calls 3

#resetIssueAggregatorMethod · 0.95
clearMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…