diff --git a/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts b/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts index 9073821da6c138..85b213e7bd3556 100644 --- a/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts +++ b/devtools/projects/ng-devtools-backend/src/lib/hooks/index.ts @@ -34,7 +34,19 @@ const endMark = (nodeName: string, method: Method) => { if (performance.getEntriesByName(start).length > 0) { // tslint:disable-next-line:ban performance.mark(end); - performance.measure(name, start, end); + + const measureOptions = { + start, + end, + detail: { + devtools: { + dataType: 'track-entry', + color: 'primary', + track: '🅰️ Angular DevTools', + }, + }, + }; + performance.measure(name, measureOptions); } performance.clearMarks(start); performance.clearMarks(end); diff --git a/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html b/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html index 6f1967fc141949..8bcbab0c9d4359 100644 --- a/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html +++ b/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html @@ -73,11 +73,13 @@ -
- - Enable timing API - -
+ @if (!profilingNotificationsSupported) { +
+ + Enable timing API + +
+ }
Dark Mode diff --git a/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts b/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts index bc19bf82d0017c..97597fd4dc85bd 100644 --- a/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts +++ b/devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts @@ -73,6 +73,9 @@ export class DevToolsTabsComponent implements OnInit, AfterViewInit { routerTreeEnabled = false; showCommentNodes = false; timingAPIEnabled = false; + profilingNotificationsSupported = Boolean( + (window.chrome?.devtools as any)?.performance?.onProfilingStarted, + ); currentTheme!: Theme; routes: Route[] = []; diff --git a/devtools/projects/shell-browser/src/app/app.component.ts b/devtools/projects/shell-browser/src/app/app.component.ts index 0b0be1916206a8..f01fda2b66dff1 100644 --- a/devtools/projects/shell-browser/src/app/app.component.ts +++ b/devtools/projects/shell-browser/src/app/app.component.ts @@ -7,6 +7,7 @@ */ import {ChangeDetectorRef, Component, inject, OnInit} from '@angular/core'; +import {Events, MessageBus} from 'protocol'; @Component({ selector: 'app-root', @@ -15,12 +16,34 @@ import {ChangeDetectorRef, Component, inject, OnInit} from '@angular/core'; }) export class AppComponent implements OnInit { private _cd = inject(ChangeDetectorRef); - + private readonly _messageBus = inject>(MessageBus); + private onProfilingStartedListener = () => { + this._messageBus.emit('enableTimingAPI'); + }; + private onProfilingStoppedListener = () => { + this._messageBus.emit('disableTimingAPI'); + }; ngOnInit(): void { chrome.devtools.network.onNavigated.addListener(() => { window.location.reload(); }); + // At the moment the chrome.devtools.performance namespace does not + // have an entry in DefinitelyTyped, so this is a temporary + // workaround to prevent TypeScript failures while the corresponding + // type is added upstream. + const chromeDevToolsPerformance = (chrome.devtools as any).performance; + chromeDevToolsPerformance?.onProfilingStarted?.addListener?.(this.onProfilingStartedListener); + chromeDevToolsPerformance?.onProfilingStopped?.addListener?.(this.onProfilingStoppedListener); this._cd.detectChanges(); } + ngOnDestroy(): void { + const chromeDevToolsPerformance = (chrome.devtools as any).performance; + chromeDevToolsPerformance?.onProfilingStarted?.removeListener?.( + this.onProfilingStartedListener, + ); + chromeDevToolsPerformance?.onProfilingStopped?.removeListener?.( + this.onProfilingStoppedListener, + ); + } }