Solvedchrome remote interface How to know where unhandled promise was triggered (Error: Promise was collected)?

Somewhere in my code I have a promise where I'm not handling a reject. It's giving me the error:

Logging in
JQMIGRATE: Migrate is installed with logging active, version 1.4.1
(node:1172) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Promise was collected
(node:1172) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Logging in
Go to NEXT page

I looked through my code a few times but didn't see an issue. The error in question is somewhere in this block:

  function login() {
    return new Promise((resolve, reject) => {
      try {
        var userEl = 'input.username';
        var passEl = 'input.password';
        document.querySelector(userEl).value = 'username';
        document.querySelector(passEl).value = 'password';
        setTimeout(resolve, 2000)
      } catch (e) {
        return reject(e);

And the block of code that triggers this is in a Runtime.evaluate block:

   let state = 'login';
    Page.loadEventFired(async() => {
      switch (state) {
        case 'login':
          console.log('Logging in');
          let res = await Runtime.evaluate({
              expression: `(${login})()`,
              awaitPromise: true,
          state = 'navigateNextPage';
          console.log('Go to NEXT page');
          await Page.navigate({
            url: 'nextPageUrl',
        case 'navigateNextPage':
some code to navigate to first login page

Seems like in the error, the first time the login invokes in the client, it fails, then the next run is successful. Is there a way to somehow print the stack trace whenever an unhandled Promise rejection occurs?

25 Answers

✔️Accepted Answer

Try with node --trace-warnings ? It'll give you a stack

Related Issues:

chrome remote interface How to know where unhandled promise was triggered (Error: Promise was collected)?
Try with node --trace-warnings ? It'll give you a stack Somewhere in my code I have a promise where ...
chrome remote interface Add TypeScript Definition File(s)
Canonical upstream issue is this: ChromeDevTools/devtools-protocol#18 Create and publish ...
next.js Module not found: Can't resolve 'fs'
Update for modern Next.js (9.4+) You can safely use fs within getStaticProps or getServerSideProps n...
mocha timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
just add in your package.json under scripts Then you can just run I'm getting the following error wh...
next.js Adding GA script tag?
No need for react-ga Use the google tag manager with the <Head> component to inject analytics ...
mocha Error: Resolution method is overspecified.
async functions (babel) with done also break. This: will result in an error Error: Resolution method...
next.js getServerSideProps cannot be serialized as JSON. Please only return JSON serializable data types
@timneutkens I don't get why this issue is closed It seems quite a lot of people are still stumbling...
mocha mocha 4 doesn't exit unlike mocha 3
Other than providing a quick fix (use --exit) I do agree they left the core issue of finding the fau...
debug npm WARN enoent ENOENT: no such file or directory, open '<root>/node_modules/supertest/package.json'
No That's not an issue of debug package I think it's related to NPM v3's changed installation behavi...
next.js Could not freeze filename
It has happened to me deleting the cache solved it rm -rf node_modules/.cache Recently I've updated ...
next.js Ability to co-locate non-page files in the pages directory
@probablyup this is so easy set pageExtensions as below a file tree like below and only /list page a...
next.js Nextjs causing hard refresh when i click in the Link
Have you tried this format for your Link? Here is a good example of this type of routing for dynamic...
next.js Link as styled component
Hey guys At version 3.0.1-beta.13+ I followed #799 but couldn't get a clean way to have a styled-com...
next.js Cannot import Typescript files from outside of 'dir' directory
If anyone needs this right now it is available as an experimental feature in 10.1.2 An example next....
next.js Image optimisation external resource not working
@raphaelbs I had a similar issue in that it worked locally but not in prod Bug report Describe the b...
next.js 8.0.0 - dynamic import causing 'You may need an appropriate loader...' error
Ok here is the winning combo (made sure is 100% reproducible): My project already had next v7 npm in...
next.js Cannot read property 'prefetch' and 'push' of null
I was able to work around the issue by mocking next/link instead of next/router: ...
mocha Async test fails with timeout instead of assertion error
I ran into a similar problem and eventually realized you shouldn't use done when testing asynchronou...
next.js Include css in a next project?
Create a /static folder at the same level the /pages folder I know that Next uses Glamor and css-in-...
next.js Handling images
@impronunciable I think its not so good idea to store all the images in the same global static folde...
next.js Generated static files html files have wrong assets paths
Thanks @cargallo 👍 Was trying to serve static exported files through an Electron app and was wonder...
next.js Next.js API routes (and pages) should support reading files
Workaround I'm using: and in the location you need the path I know this doesn't solve the need to re...
next.js Error after upgrading from 9.3.6 to 9.4
@aralroca Have you tried deleting the .next directory and running npm run dev again? ...
next.js Dev mode on Next.js v12 breaks with combination of features
This seems to be a particular case with Chakra UI and some other deps As a temporary workaround you ...
next.js How to mock useRouter?
I ended up mocking it like this I only need the useRouter export so this worked well enough for my p...
next.js [Next 9.0] How to remove the clickable label "Prerendered Page" and loading Icon ? I want to remove Prerendered Page label and i...
next.js Add a Dynamic Sitemap example that works with the new Dynamic Routes
I am making use of the new rewrites feature of NextJS v9.1.4 Inside of pages/api/sitemap.ts I run th...
next.js Getting ReactDOMServer does not yet support Suspense error while using styled-components
In my case following error Error: ReactDOMServer does not yet support Suspense What version of Next....
next.js False positive report of "API resolved without sending a response"
@gaku-sei it is most likely caused by the callback as we can't detect you are still doing work in th...
next.js Provide example using Context API with custom _app.js
I have an example if anyone wants to clean it up and turn it into a PR: NoteProvider.js _app.js Then...
next.js css-loader + CSS modules pure selectors
I solved my issues by moving away from implicit HTML calls (ex: nav and <nav> ) for specific element...
next.js Feature request: Basepath support
Any update on this.. last year around this time i ran into this issue Now a year later ...
next.js SVGR fails to load SVGs with Next 11
The fix is available in next@11.0.1-canary.4 You can try it out today with yarn add next@canary Than...
next.js Route matching with params
@dstreet Personally I think package.json should only contain NPM configuration (i.e dependencies scr...
next.js Non-standardized PostCSS config file doesn't support require statements
the workaround Bug report Describe the bug With the introduction of the marvelous Built-in CSS Suppo...
mocha Cannot find module 'tap', but tap isn't listed as a dependency
It's something I run into as well I think that 's because you run a test from your node_modules ...
next.js Support ES module format (ESM) in next.config.js
I've opened a PR that changes from require() to import() for config loading and adds support for nex...
next.js Feasibility of micro frontends
@janus-reith Thank you I've been really frustrated that nobody actually solved this ...
next.js next dev rewrites tsconfig.json
isolatedModules is certainly debatable – for example we'd like to make a tradeoff between performanc...
next.js next/image memory leak?
Hi I'm the sharp maintainer and I've just been made aware that Next.js switched away from using it d...
next.js Unable to import module 'now__launcher'
Because this is the first result in google and there is no link to the other issue ...
next.js A first-class way to internationalize a statically exported Next.js app
Alright! Here's a summary of what I did for future adventurers: First in your next config ...
next.js [RFC] CSS Support
Whatever we do here can we make sure it's still easy to use custom PostCSS plugins like it is now wi...
next.js with-redux-persist SSR issue
@jeffersoncustodio820 Your solution is good but this causes ReactDOM.hydrate to throw an HTML mismat...
next.js Custom loaders are not recognized by next export
Potentially related FWIW What version of Next.js...
next.js Error: Cannot find module 'webpack'
This happens because Next.js 10.0.6 introduces support for dual-loading webpack as part of our work ...
next.js Elegance of dynamic imports in TypeScript
I also had same problem and solved it in a way of which makes use of generics First you should defin...
next.js Truly static pages without react app
I also did something similar to @danielr18 The problem with his example is that JavaScript files are...
next.js “transform-decorators-legacy” does not work with next@7
I use [@babel/plugin-proposal-decorators { legacy: true }] and this works for me ...
next.js Browser Back Button does not trigger window.onbeforeunload
Thanks for that snippet @Fensterbank Super useful I did notice one possible issue with it ...