Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a React/Redux app that I am testing using Puppeteer. Based on the documentation, I am using the following code to show the console outputs:

page.on('console', msg => {
    for(let i = 0; i < msg.args().length; ++i) {
        let text = msg.args()[i];
        console.log(`${i}: ${text}`);
    }
});

However, when the redux-logger logs an object to console (prevState, nextState), Puppeeter shows JSHandle@object in my console outputs instead. How do I see the keys and properties inside this object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
719 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you place the consoleMessage.args() directly inside console.log() without enclosing them in template literals, you can print the keys and values of the JSHandles that represent each argument passed to console.log() in the page context:

page.on('console', msg => {
  for (let i = 0; i < msg.args().length; i++) {
    console.log(msg.args()[i]);
  }
});

The beginning of the result will look something like this:

JSHandle {
  _context:
   ExecutionContext {
     _client:
      CDPSession {
        domain: null,
        _events: [Object],
        ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...