11import { LogEventType } from '../../constants/internal' ;
2+ import { addPageToApiStatistics } from '../../utils/apiStatistics' ;
23import { getDocumentUrl } from '../../utils/document' ;
34import { getDurationWithUnits } from '../../utils/getDurationWithUnits' ;
45import { log } from '../../utils/log' ;
56
67import { createPageInstance } from './createPageInstance' ;
78
8- import type { AnyPageClassType , NavigateToOrAssertPageArgs , UtcTimeInMs } from '../../types/internal' ;
9+ import type {
10+ AnyPageClassType ,
11+ NavigateToOrAssertPageArgs ,
12+ PageName ,
13+ UtcTimeInMs ,
14+ } from '../../types/internal' ;
915
1016/**
1117 * Navigates to the page by page class and page params.
@@ -24,9 +30,10 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
2430 const url = route . getUrl ( ) ;
2531 const startNavigateTimeInMs = Date . now ( ) as UtcTimeInMs ;
2632 const pageInstanceCreatedInMs = startNavigateTimeInMs - startTimeInMs ;
33+ const pageName = PageClass . name as PageName ;
2734
2835 log (
29- `Will navigate to the page "${ PageClass . name } "` ,
36+ `Will navigate to the page "${ pageName } "` ,
3037 { pageInstanceCreatedInMs, pageParams, routeParams, url} ,
3138 LogEventType . InternalAction ,
3239 ) ;
@@ -36,7 +43,7 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
3643 await page . navigateToPage ( url ) ;
3744
3845 log (
39- `Navigation to the page "${ PageClass . name } " completed` ,
46+ `Navigation to the page "${ pageName } " completed` ,
4047 { pageParams, routeParams, url} ,
4148 LogEventType . InternalAction ,
4249 ) ;
@@ -52,13 +59,12 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
5259
5360 await page . afterNavigateToPage ?.( ) ;
5461
55- const durationWithUnits = getDurationWithUnits ( Date . now ( ) - startNavigateTimeInMs ) ;
62+ const duration = Date . now ( ) - startNavigateTimeInMs ;
63+ const durationWithUnits = getDurationWithUnits ( duration ) ;
5664
57- log (
58- `Page "${ PageClass . name } " loaded in ${ durationWithUnits } ` ,
59- { url} ,
60- LogEventType . InternalAction ,
61- ) ;
65+ log ( `Page "${ pageName } " loaded in ${ durationWithUnits } ` , { url} , LogEventType . InternalAction ) ;
66+
67+ addPageToApiStatistics ( { duration, pageName, url} ) ;
6268
6369 return page ;
6470} ;
0 commit comments