@@ -6,6 +6,8 @@ import { watchPageErrors } from "../browser/page-errors.mjs";
66// A Playwright page reduced to the events and browser identity the watcher reads.
77const fakePage = ( engine ) => {
88 const page = new EventEmitter ( ) ;
9+ const mainFrame = { } ;
10+ page . mainFrame = ( ) => mainFrame ;
911 page . context = ( ) => ( {
1012 browser : ( ) => ( { browserType : ( ) => ( { name : ( ) => engine } ) } ) ,
1113 } ) ;
@@ -68,6 +70,62 @@ test("the access-control log fails without a matching cancelled request", () =>
6870 }
6971} ) ;
7072
73+ // Replayed from the Linux WebKit trace of channel-archive-delete-pane.spec.mjs:28
74+ // on main (run 37478134645 for 2bb37a55): a presence timer fired during the
75+ // reload, and WebKit refused both fetches without a request event.
76+ const presenceAuthors =
77+ "http://127.0.0.1:40091/api/relay/primary/stream-presence-authors" ;
78+ const navigate = ( page , frame = page . mainFrame ( ) ) => {
79+ const request = {
80+ isNavigationRequest : ( ) => true ,
81+ frame : ( ) => frame ,
82+ url : ( ) => "http://127.0.0.1:40091/" ,
83+ failure : ( ) => ( { errorText : "Load request cancelled" } ) ,
84+ } ;
85+ page . emit ( "request" , request ) ;
86+ return request ;
87+ } ;
88+
89+ test ( "WebKit's log for a fetch refused while the document is replaced is explained" , ( ) => {
90+ const page = fakePage ( "webkit" ) ;
91+ const watched = watchPageErrors ( page ) ;
92+ navigate ( page ) ;
93+ page . emit ( "pageerror" , reloadCancelLog ( presenceAuthors ) ) ;
94+ page . emit ( "framenavigated" , page . mainFrame ( ) ) ;
95+ assert . deepEqual ( watched . errors , [
96+ `Fetch API cannot load ${ presenceAuthors } due to access control checks.` ,
97+ ] ) ;
98+ assert . deepEqual ( watched . unexplained ( ) , [ ] ) ;
99+ } ) ;
100+
101+ test ( "only the main frame's pending navigation explains a refused fetch" , ( ) => {
102+ for ( const setup of [
103+ // The new document has committed.
104+ ( page ) => {
105+ navigate ( page ) ;
106+ page . emit ( "framenavigated" , page . mainFrame ( ) ) ;
107+ } ,
108+ // The navigation failed, so the old document stays.
109+ ( page ) => page . emit ( "requestfailed" , navigate ( page ) ) ,
110+ // A child frame navigates.
111+ ( page ) => navigate ( page , { } ) ,
112+ ] ) {
113+ const page = fakePage ( "webkit" ) ;
114+ const watched = watchPageErrors ( page ) ;
115+ setup ( page ) ;
116+ page . emit ( "pageerror" , reloadCancelLog ( presenceAuthors ) ) ;
117+ assert . equal ( watched . unexplained ( ) . length , 1 ) ;
118+ }
119+ } ) ;
120+
121+ test ( "a pending navigation does not explain other page errors" , ( ) => {
122+ const page = fakePage ( "webkit" ) ;
123+ const watched = watchPageErrors ( page ) ;
124+ navigate ( page ) ;
125+ page . emit ( "pageerror" , new TypeError ( "a: b" ) ) ;
126+ assert . deepEqual ( watched . unexplained ( ) , [ "TypeError: a: b" ] ) ;
127+ } ) ;
128+
71129test ( "one cancellation explains one log" , ( ) => {
72130 const page = fakePage ( "webkit" ) ;
73131 const watched = watchPageErrors ( page ) ;
@@ -77,6 +135,18 @@ test("one cancellation explains one log", () => {
77135 assert . equal ( watched . unexplained ( ) . length , 1 ) ;
78136} ) ;
79137
138+ test ( "a log during navigation uses up its cancellation" , ( ) => {
139+ const page = fakePage ( "webkit" ) ;
140+ const watched = watchPageErrors ( page ) ;
141+ navigate ( page ) ;
142+ cancel ( page , query ) ;
143+ page . emit ( "pageerror" , reloadCancelLog ( ) ) ;
144+ page . emit ( "framenavigated" , page . mainFrame ( ) ) ;
145+ // The new document reports the same URL without a new cancellation.
146+ page . emit ( "pageerror" , reloadCancelLog ( ) ) ;
147+ assert . equal ( watched . unexplained ( ) . length , 1 ) ;
148+ } ) ;
149+
80150test ( "an unhandled rejection is never an engine report" , ( ) => {
81151 const page = fakePage ( "webkit" ) ;
82152 const watched = watchPageErrors ( page ) ;
0 commit comments