Puppeteer auth script not working
See original GitHub issueDescribe the bug
I have a puppeteer script that logs in to my site, so I can run lighthouse against authenticated pages.
When I run this in headed mode, I see Chrome login as expected.
However, when I check the test output, all the screenshots clearly show the login page, so it’s as if lighthouse has ignored the puppeteer script entirely.
To Reproduce Steps to reproduce the behavior:
const puppeteer = require("puppeteer");
const user = process.env.USER;
const password = process.env.PASSWORD;
const siteOrigin = process.env.SITE_ORIGIN;
module.exports = async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`${siteOrigin}/sign_in`);
await page.type("input#user_email", user);
await page.type("input#user_password", password);
await page.click('input[type="submit"]');
await page.waitForNavigation();
await page.close();
};
module.exports = {
ci: {
collect: {
settings: {
disableStorageReset: true,
},
upload: {
target: "temporary-public-storage",
},
isSinglePageApplication: true,
puppeteerScript: "./src/event.js",
url: [
"https://mywebsite.com/account",
],
},
},
};
Expected behavior I would expect the lighthouse test to test against the logged in page.
Environment (please complete the following information):
- OS: Mac OS
- Browser Chrome
- Version 88.0.4324.96
Additional context
It’s worth mentioning I’ve tried this with and without the page.close()
step.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Unable to login with Puppeteer - node.js - Stack Overflow
This error occurred because you are setting email and password by executing a javascript function $eval instead of the type function.
Read more >site login malfunction under puppeteer that does not occur ...
Run script, Chrome window opens. · Enter https://online.citi.com in address bar, home page opens showing Sign On section. · Enter 'aaa' in User...
Read more >Using cookies to speed up Puppeteer and Playwright scripts
Reading or modifying cookies opens up useful possibilities. A practical example is skipping authentication when testing features available only after login. We ...
Read more >Web Scraping with a Headless Browser: A Puppeteer Tutorial
In this article, Toptal Freelance JavaScript Developer Nick Chikovani shows how easy it is to perform web scraping using a headless browser.
Read more >Puppeteer | webhint documentation
All properties of options are optional. auth : The credentials and elements to authenticate on a website. See next section for further details....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Did you already address this? This was the headline of my comment and the reason the script you provided will never work. The storage reset comment was just an extra aside.
So for the benefit of anyone else who stumbles upon this, here’s the finished code that does now work:
As you can see, I just needed to use the provided
browser
instance, just as @patrickhulce suggested.Thanks! 🎉