@@ -275,6 +275,64 @@ describe('pages', () => {
275275 assert . ok ( response . includePages ) ;
276276 } ) ;
277277 } ) ;
278+
279+ it ( 'creates a page in a fresh incognito context' , async ( ) => {
280+ await withMcpContext ( async ( response , context ) => {
281+ await newPage ( ) . handler (
282+ { params : { url : 'about:blank' , incognito : true } } ,
283+ response ,
284+ context ,
285+ ) ;
286+ const page = context . getSelectedPptrPage ( ) ;
287+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
288+ assert . ok ( isolatedContextName ) ;
289+ assert . ok ( isolatedContextName . startsWith ( 'incognito-context-' ) ) ;
290+ assert . ok ( response . includePages ) ;
291+ } ) ;
292+ } ) ;
293+
294+ it ( 'creates a new context for each incognito page' , async ( ) => {
295+ await withMcpContext ( async ( response , context ) => {
296+ await newPage ( ) . handler (
297+ { params : { url : 'about:blank' , incognito : true } } ,
298+ response ,
299+ context ,
300+ ) ;
301+ const page1 = context . getSelectedPptrPage ( ) ;
302+ const isolatedContext1 = context . getIsolatedContextName ( page1 ) ;
303+
304+ await newPage ( ) . handler (
305+ { params : { url : 'about:blank' , incognito : true } } ,
306+ response ,
307+ context ,
308+ ) ;
309+ const page2 = context . getSelectedPptrPage ( ) ;
310+ const isolatedContext2 = context . getIsolatedContextName ( page2 ) ;
311+
312+ assert . notStrictEqual ( page1 . browserContext ( ) , page2 . browserContext ( ) ) ;
313+ assert . notStrictEqual ( isolatedContext1 , isolatedContext2 ) ;
314+ } ) ;
315+ } ) ;
316+
317+ it ( 'throws when incognito and isolatedContext are both provided' , async ( ) => {
318+ await withMcpContext ( async ( response , context ) => {
319+ await assert . rejects (
320+ ( ) =>
321+ newPage ( ) . handler (
322+ {
323+ params : {
324+ url : 'about:blank' ,
325+ incognito : true ,
326+ isolatedContext : 'session-a' ,
327+ } ,
328+ } ,
329+ response ,
330+ context ,
331+ ) ,
332+ / m u t u a l l y e x c l u s i v e / ,
333+ ) ;
334+ } ) ;
335+ } ) ;
278336 } ) ;
279337 describe ( 'new_page with isolatedContext' , ( ) => {
280338 it ( 'creates a page in an isolated context' , async ( ) => {
0 commit comments