question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to get in console.log a specific text message, from console within devtools

See original GitHub issue

Hi, I am trying to get specific text message to appear in console.log, which existed in console within devtool (when i add “&debug=true” at the end of url), i am trying following but msg.args prints out all kind of messages. is there a better way to handle\streamline the args?

const page = await browser.newPage(); await page.goto(‘URL&debug=true’);

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
aslushnikovcommented, Jun 22, 2020

I’ll complement this with a snippet:

const {webkit} = require('playwright');

(async () => {
  const browser = await webkit.launch();
  const page = await browser.newPage();
  const [msg] = await Promise.all([
    page.waitForEvent('console'),
    page.evaluate(() => {
      // Issue console.log statements inside the page.
      console.log('hello, world', 42, {foo: 'bar'});
    }),
  ]);

  // serialize and print all console.log arguments one-by-one.
  for (const arg of msg.args())
    console.log(await arg.jsonValue());
  await browser.close();
})();
3reactions
pavelfeldmancommented, Jun 20, 2020

console.log(42, 'hello', true);

await msg.args[0].jsonValue() // will give you 42
await msg.args[1].jsonValue() // will give you 'hello'

etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to log messages in the Console | DevTools Tips - YouTube
In this episode, Bramus and Jecelyn walk you through the different ways of logging and filtering messages in the Console.
Read more >
Log messages in the Console - Chrome Developers
Focus the demo and then press Control + Shift + J or Command + Option + J (Mac) to open DevTools. By default...
Read more >
How to read from Chrome's console in JavaScript
What's in the console can't be read from JavaScript. What you can do is hook the console.log function so that you store when...
Read more >
How to Style console.log Contents in Chrome DevTools
Learn how the console. log output can be styled in DevTools using the CSS format specifier. We'll also touch on manipulating console.
Read more >
Copy JSON from console.log in developer tool to clipboard?
@EdwinSnts Bertrand means in the Javascript console, after logging an object with console.log( myObject ) , to right click on that object. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found