2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ * *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  2017  Google  Inc .  All  rights  reserved . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Modifications  copyright  ( c )  Microsoft  Corporation . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Licensed  under  the  Apache  License ,  Version  2.0  ( the  "License" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  you  may  not  use  this  file  except  in  compliance  with  the  License . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  You  may  obtain  a  copy  of  the  License  at 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *      http : //www.apache.org/licenses/LICENSE-2.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Unless  required  by  applicable  law  or  agreed  to  in  writing ,  software 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  distributed  under  the  License  is  distributed  on  an  "AS IS"  BASIS , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  WITHOUT  WARRANTIES  OR  CONDITIONS  OF  ANY  KIND ,  either  express  or  implied . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  See  the  License  for  the  specific  language  governing  permissions  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  limitations  under  the  License . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  *  as  frames  from  './frame' ;  
						 
					
						
							
								
									
										
										
										
											2020-07-14 07:03:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  Page ,  BindingCall  }  from  './page' ;  
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  *  as  network  from  './network' ;  
						 
					
						
							
								
									
										
										
										
											2020-08-25 08:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  *  as  channels  from  '../protocol/channels' ;  
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  ChannelOwner  }  from  './channelOwner' ;  
						 
					
						
							
								
									
										
										
										
											2020-08-22 22:07:13 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  deprecate ,  evaluationScript ,  urlMatches  }  from  './clientHelper' ;  
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  Browser  }  from  './browser' ;  
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  Events  }  from  './events' ;  
						 
					
						
							
								
									
										
										
										
											2020-08-23 06:13:51 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  TimeoutSettings  }  from  '../utils/timeoutSettings' ;  
						 
					
						
							
								
									
										
										
										
											2020-07-14 07:03:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  Waiter  }  from  './waiter' ;  
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  {  URLMatch ,  Headers ,  WaitForEventOptions  }  from  './types' ;  
						 
					
						
							
								
									
										
										
										
											2020-09-07 12:36:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  isUnderTest ,  headersObjectToArray  }  from  '../utils/utils' ;  
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-25 08:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export  class  BrowserContext  extends  ChannelOwner < channels.BrowserContextChannel ,  channels.BrowserContextInitializer >  {  
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  _pages  =  new  Set < Page > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  private  _routes :  {  url : URLMatch ,  handler : network.RouteHandler  } [ ]  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 06:26:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  readonly  _browser : Browser  |  undefined ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 12:46:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  readonly  _browserName : string ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 02:51:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  readonly  _bindings  =  new  Map < string ,  frames.FunctionWithSource > ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 12:22:03 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  _timeoutSettings  =  new  TimeoutSettings ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-30 07:37:38 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  _ownerPage : Page  |  undefined ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-10 06:33:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  private  _isClosedOrClosing  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  private  _closedPromise : Promise < void > ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-25 08:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  static  from ( context : channels.BrowserContextChannel ) :  BrowserContext  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-02 09:36:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  ( context  as  any ) . _object ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-25 08:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  static  fromNullable ( context : channels.BrowserContextChannel  |  null ) :  BrowserContext  |  null  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  context  ?  BrowserContext . from ( context )  :  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-25 08:05:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  constructor ( parent : ChannelOwner ,  type :  string ,  guid : string ,  initializer : channels.BrowserContextInitializer ,  browserName : string )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-28 01:21:39 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    super ( parent ,  type ,  guid ,  initializer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 12:46:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( parent  instanceof  Browser ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 06:26:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      this . _browser  =  parent ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 12:46:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _browserName  =  browserName ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 06:26:09 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-15 09:26:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . on ( 'bindingCall' ,  ( { binding } )  = >  this . _onBinding ( BindingCall . from ( binding ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-01 01:55:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . on ( 'close' ,  ( )  = >  this . _onClose ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-15 09:26:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . on ( 'page' ,  ( { page } )  = >  this . _onPage ( Page . from ( page ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-01 01:55:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . on ( 'route' ,  ( {  route ,  request  } )  = >  this . _onRoute ( network . Route . from ( route ) ,  network . Request . from ( request ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-10 06:33:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _closedPromise  =  new  Promise ( f  = >  this . once ( Events . BrowserContext . Close ,  f ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 03:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  private  _onPage ( page : Page ) :  void  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this . _pages . add ( page ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this . emit ( Events . BrowserContext . Page ,  page ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 02:51:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  _onRoute ( route : network.Route ,  request : network.Request )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  { url ,  handler }  of  this . _routes )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-20 04:27:58 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      if  ( urlMatches ( request . url ( ) ,  url ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 02:51:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        handler ( route ,  request ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    route . continue ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  _onBinding ( bindingCall : BindingCall )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 03:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    const  func  =  this . _bindings . get ( bindingCall . _initializer . name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 02:51:47 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( ! func ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bindingCall . call ( func ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  setDefaultNavigationTimeout ( timeout : number )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 07:03:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _timeoutSettings . setDefaultNavigationTimeout ( timeout ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . setDefaultNavigationTimeoutNoReply ( {  timeout  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  setDefaultTimeout ( timeout : number )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 12:22:03 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _timeoutSettings . setDefaultTimeout ( timeout ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _channel . setDefaultTimeoutNoReply ( {  timeout  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  pages ( ) :  Page [ ]  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  [ . . . this . _pages ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  newPage ( ) :  Promise < Page >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.newPage' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( this . _ownerPage ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        throw  new  Error ( 'Please use browser.newContext()' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return  Page . from ( ( await  this . _channel . newPage ( ) ) . page ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  cookies ( urls? : string  |  string [ ] ) :  Promise < network.NetworkCookie [ ] >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! urls ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      urls  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( urls  &&  typeof  urls  ===  'string' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      urls  =  [  urls  ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.cookies' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return  ( await  this . _channel . cookies ( {  urls : urls  as  string [ ]  } ) ) . cookies ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  addCookies ( cookies : network.SetNetworkCookieParam [ ] ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.addCookies' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . addCookies ( {  cookies  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  clearCookies ( ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.clearCookies' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . clearCookies ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  grantPermissions ( permissions : string [ ] ,  options ? :  {  origin? : string  } ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.grantPermissions' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . grantPermissions ( {  permissions ,  . . . options  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  clearPermissions ( ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.clearPermissions' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . clearPermissions ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  setGeolocation ( geolocation :  {  longitude : number ,  latitude : number ,  accuracy? : number  }  |  null ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.setGeolocation' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 08:38:06 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . setGeolocation ( {  geolocation : geolocation  ||  undefined  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  setExtraHTTPHeaders ( headers : Headers ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.setExtraHTTPHeaders' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-19 06:38:29 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      network . validateHeaders ( headers ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . setExtraHTTPHeaders ( {  headers : headersObjectToArray ( headers )  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  setOffline ( offline : boolean ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.setOffline' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . setOffline ( {  offline  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  setHTTPCredentials ( httpCredentials :  {  username : string ,  password : string  }  |  null ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 12:36:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! isUnderTest ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-18 07:19:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      deprecate ( ` context.setHTTPCredentials ` ,  ` warning: method |context.setHTTPCredentials()| is deprecated. Instead of changing credentials, create another browser context with new credentials. ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.setHTTPCredentials' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-21 08:38:06 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . setHTTPCredentials ( {  httpCredentials : httpCredentials  ||  undefined  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  addInitScript ( script : Function  |  string  |  {  path? : string ,  content? : string  } ,  arg? : any ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.addInitScript' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-20 04:27:58 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      const  source  =  await  evaluationScript ( script ,  arg ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . addInitScript ( {  source  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-01 08:00:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  exposeBinding ( name : string ,  playwrightBinding : frames.FunctionWithSource ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.exposeBinding' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      for  ( const  page  of  this . pages ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( page . _bindings . has ( name ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          throw  new  Error ( ` Function " ${ name } " has been already registered in one of the pages ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( this . _bindings . has ( name ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        throw  new  Error ( ` Function " ${ name } " has been already registered ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-01 08:00:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      this . _bindings . set ( name ,  playwrightBinding ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      await  this . _channel . exposeBinding ( {  name  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  exposeFunction ( name : string ,  playwrightFunction : Function ) :  Promise < void >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await  this . exposeBinding ( name ,  ( source ,  . . . args )  = >  playwrightFunction ( . . . args ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  route ( url : URLMatch ,  handler : network.RouteHandler ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.route' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this . _routes . push ( {  url ,  handler  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( this . _routes . length  ===  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  this . _channel . setNetworkInterceptionEnabled ( {  enabled : true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  unroute ( url : URLMatch ,  handler? : network.RouteHandler ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.unroute' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this . _routes  =  this . _routes . filter ( route  = >  route . url  !==  url  ||  ( handler  &&  route . handler  !==  handler ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( this . _routes . length  ===  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  this . _channel . setNetworkInterceptionEnabled ( {  enabled : false  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 08:26:59 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  waitForEvent ( event : string ,  optionsOrPredicate : WaitForEventOptions  =  { } ) :  Promise < any >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 13:38:52 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    const  timeout  =  this . _timeoutSettings . timeout ( typeof  optionsOrPredicate  ===  'function'   ?  { }  :  optionsOrPredicate ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  predicate  =  typeof  optionsOrPredicate  ===  'function'   ?  optionsOrPredicate  : optionsOrPredicate.predicate ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 07:03:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    const  waiter  =  new  Waiter ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-22 14:48:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    waiter . rejectOnTimeout ( timeout ,  ` Timeout while waiting for event " ${ event } " ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 07:03:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( event  !==  Events . BrowserContext . Close ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      waiter . rejectOnEvent ( this ,  Events . BrowserContext . Close ,  new  Error ( 'Context closed' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  result  =  await  waiter . waitForEvent ( this ,  event ,  predicate  as  any ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    waiter . dispose ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 12:22:03 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-14 04:24:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  async  _onClose() { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-10 06:33:01 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . _isClosedOrClosing  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 08:24:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( this . _browser ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      this . _browser . _contexts . delete ( this ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-27 03:28:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this . emit ( Events . BrowserContext . Close ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-01 01:55:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  async  close ( ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-17 05:32:21 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    return  this . _wrapApiCall ( 'browserContext.close' ,  async  ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( ! this . _isClosedOrClosing )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . _isClosedOrClosing  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  this . _channel . close ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  this . _closedPromise ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-01 01:55:11 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-26 07:05:36 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}