Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add --puppeteer-script flag to collect #118

Merged
merged 2 commits into from Nov 26, 2019

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Nov 26, 2019

closes #89

Usage looks like:

lhci collect \
  --start-server-command="yarn serve" \
  --url=http://localhost:8080/ \
  --puppeteer-script=./path/to/login-with-puppeteer.js

Example login-with-puppeteer.js

/**
 * @param {puppeteer.Browser} browser
 * @param {{url: string, options: LHCI.CollectOptions}} context
 */
module.exports = async (browser, context) => {
  const page = await browser.newPage();
  await page.goto('http://localhost:8080/login');
  await page.type('#username', 'admin');
  await page.type('#password', 'password');
  await page.click('[type="submit"]');
  await page.waitForNavigation();
};

};
```

Lighthouse CI will then use this browser that the script sets up when running Lighthouse. Note that if you store your credentials in `localStorage` or anything other than a cookie you might want to pair this option with `--settings.disableStorageReset` to force Lighthouse to keep the cache state.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to our auth docs too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's linked in troubleshooting.

@@ -1,8 +1,7 @@
#!/bin/bash

CURRENT_VERSION=$(node -e "console.log(require('./package.json').dependencies['@lhci/server'])")
# NEXT_VERSION=$(yarn info @lhci/server | grep 'latest:' -A 1 | tail -n 1 | grep -o "'.*'" | sed s/\'//g)
NEXT_VERSION=0.3.3
NEXT_VERSION=$(yarn info @lhci/server | grep 'latest:' -A 1 | tail -n 1 | grep -o "'.*'" | sed s/\'//g)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woah. maybe do a call to node like the line above? this is inscrutable :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing it all in node would be at least a dozen lines though :)

packages/cli/src/collect/puppeteer-manager.js Outdated Show resolved Hide resolved
docs/cli.md Outdated
```js
/**
* @param {puppeteer.Browser} browser
* @param {{url: string, options: LHCI.CollectOptions}} context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this type is defined anywhere. is it {url:string, options: LHCI.Options}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's not it was meant to just be user friendly "here are the collect options" but i'll use the real one :)

@patrickhulce patrickhulce merged commit ac0f345 into master Nov 26, 2019
@patrickhulce patrickhulce deleted the puppeteer_script branch November 26, 2019 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for --puppeteer-script
2 participants