@@ -7,10 +7,18 @@ import {CREATE_PAGE_TOKEN} from './constants/internal';
77import { assertValueIsTrue } from './utils/asserts' ;
88import { getFullPackConfig } from './utils/config' ;
99import { reloadDocument } from './utils/document' ;
10+ import { setReadonlyProperty } from './utils/object' ;
1011import { getPlaywrightPage } from './useContext' ;
1112
1213import type { PageRoute } from './PageRoute' ;
13- import type { AsyncVoid , NavigateToUrlOptions , PageClassTypeArgs , Url } from './types/internal' ;
14+ import type {
15+ AsyncVoid ,
16+ NavigateToUrlOptions ,
17+ NavigationReturn ,
18+ PageClassTypeArgs ,
19+ StatusCode ,
20+ Url ,
21+ } from './types/internal' ;
1422
1523/**
1624 * Abstract page with base methods.
@@ -43,6 +51,11 @@ export abstract class Page<PageParams = undefined> {
4351 */
4452 readonly pageParams : PageParams ;
4553
54+ /**
55+ * Status code of page, if any.
56+ */
57+ readonly statusCode : StatusCode | undefined ;
58+
4659 constructor ( ...args : PageClassTypeArgs < PageParams > ) {
4760 const [ createPageToken , pageParams ] = args ;
4861
@@ -112,8 +125,21 @@ export abstract class Page<PageParams = undefined> {
112125 /**
113126 * Navigates to the page by url.
114127 */
115- navigateToPage ( url : Url , options ?: NavigateToUrlOptions ) : Promise < void > {
116- return navigateToUrl ( url , { skipLogs : true , timeout : this . navigationTimeout , ...options } ) ;
128+ async navigateToPage (
129+ this : Page ,
130+ url : Url ,
131+ options ?: NavigateToUrlOptions ,
132+ ) : Promise < NavigationReturn > {
133+ const navigationReturn = await navigateToUrl ( url , {
134+ skipLogs : true ,
135+ timeout : this . navigationTimeout ,
136+ ...options ,
137+ } ) ;
138+ const { statusCode} = navigationReturn ;
139+
140+ setReadonlyProperty ( this , 'statusCode' , statusCode ) ;
141+
142+ return navigationReturn ;
117143 }
118144
119145 /**
0 commit comments