This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Error UnhandledPromiseRejectionWarning: TypeError: page.reload is not a function

 
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am new to node.js

I am getting the following error

UnhandledPromiseRejectionWarning: TypeError: page.reload is not a function


The problem is that the await object page that is returned is not the await object I created.

Thanks for any help
 
Tony Evans
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a fix.



 
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your first monitor function, you didn't use await with page, so it is a promise, and promises don't have a reload function. If you use let page = await configureBrowser().catch(...), the return type changes into Page | void: Page if the promise is resolved, void if the promise is rejected (because the catch clause returns nothing).

I've created a little TypeScript project for this (creating simple interfaces for the puppeteer, browser and page objects), and the following monitor function compiles just fine:

The if (page) is necessary to handle the rejected promise.
 
Rob Spoor
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PS: because both of the above are mixing await, then and catch, here's a better example:

I think the await isn't even necessary anymore[/tt] (and neither is the async).
 
Tony Evans
Ranch Hand
Posts: 680
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks, I am going by youtube tutorials, which never seem to work as they are out of date and the code evolves, but I am learning
reply
    Bookmark Topic Watch Topic
  • New Topic