Last active
          March 9, 2023 21:42 
        
      - 
      
- 
        Save hendrixroa/ee4f4500de13ec1303e1a74bc6c88a35 to your computer and use it in GitHub Desktop. 
    Get page function to open a headless browser window
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public async getPage() { | |
| if (!this.browser) { | |
| await this.initBrowser(); | |
| } | |
| const page = await this.browser.newPage(); | |
| // Avoiding Bot detection | |
| const userAgent = | |
| 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36'; | |
| await page.setUserAgent(userAgent); | |
| page.on('console', msg => { | |
| this.emit('console', msg.text()); | |
| }); | |
| return page; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment