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 know that browser is opened with Puppeteer

See original GitHub issue

Is there a way to know (from page’s JS) that the browser is running with Puppeteer? I saw the tip to check for headless string in userAgent, but I’m running with headless: false (testing extension). I’d like to switch some features if the extension is run in tests.

Issue Analytics

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

github_iconTop GitHub Comments

15reactions
aslushnikovcommented, Jan 4, 2018

@skyiea you can launch chrome with a custom user agent:

const puppeteer = require('puppeteer');

(async() => {

  const browser = await puppeteer.launch({
    args: ['--user-agent=hhh'],
  });
  const page = await browser.newPage();
  console.log(await page.evaluate(() => navigator.userAgent));
  await browser.close();
})();

Hope this helps

6reactions
yujiosakacommented, Dec 31, 2017

@skyiea How about setting a user agent like ‘puppeteer’, so that you know from window.navigator.userAgent ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

puppeteer : how check if browser is still open and working
You can use browser.on('disconnected') to listen for when the browser is closed or crashed, or if the browser.disconnect() method was called.
Read more >
Getting to Know Puppeteer Using Practical Examples
Puppeteer launches the browser in a headless mode by default, which merely uses the command line. Also - a headful mode, for opening...
Read more >
How To Write End-to-End Tests in Node.js Using Puppeteer ...
The web crawler will open a browser, navigate to the Login page, and enter the credentials, then the test script will run to...
Read more >
Puppeteer | Puppeteer
// Type into search box. await page.type('.devsite-search-field', 'Headless Chrome'); // Wait for suggest overlay to appear and click "show all results". const ...
Read more >
How to Use Puppeteer With Node.js - freeCodeCamp
Puppeteer lets you automate the testing of your web applications. With it, you can run tests in the browser and then see the...
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