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

Docs on how to run int programmatically? #106

Closed
AlEsGoGit opened this issue May 17, 2023 · 6 comments
Closed

Docs on how to run int programmatically? #106

AlEsGoGit opened this issue May 17, 2023 · 6 comments

Comments

@AlEsGoGit
Copy link

AlEsGoGit commented May 17, 2023

Details

Hello!.
I need to launch lighthouse for ci purposes, so looking for documentation i got to this repo.
I think its amazing, but im having problems trying to use it as a part of a node module.
Am i missing something or theres is not docs about this topic?
It will be great.
Thank you!

Edit:
https://github.com/GoogleChrome/lighthouse/tree/main/docs/recipes/auth
Thats the reason.
I need to make a login in one web app and then audit the app while keep the login.

@harlan-zw
Copy link
Owner

Hi @AlEsGoGit, thanks for the issue :)

I've expanded the Authentication docs to include an authentication example, see here.

Let me know if that's not clear or you have issues.

@AlEsGoGit
Copy link
Author

Thats nice, thank you.
But it has a problem.
It indeed allows you to log in manually using a form displayed in your web, but yo lose the page context cause you are doing a "manual" goto to the login page, so the lighthouse test runs over the login parge or wherever it redirects you after the login.

Thanks.

@harlan-zw
Copy link
Owner

Hmm I see. Personally I haven't ever needed this functionlity so have limited functionality and testing around it. I want to provide support for it.

Would it be possible to provide a flow on the site you're trying to get authentication working for? Happy to create an account on it if needed.

@AlEsGoGit
Copy link
Author

AlEsGoGit commented May 21, 2023

Im using laravel for my app, so the basic flow is a login page that redirects you to the requested page when you log in.
So when i provide an url, inside the "before go to" hook, i can use puppeteer to log in, but after that, puppeteer fails due to this redirect.

"Error "We have an error Error: the execution context was destroyed, probably because of a navigation."

Lighthouse solves this allowing you to pass a page instance that its already logged as a parameter for the lighthouse function:
https://github.com/GoogleChrome/lighthouse/tree/main/docs/recipes/auth

Thats why i asked if there is an option to use unlighthouse inside a node script instead a cli command with an option file.
Somthing like this:
https://unlighthouse.dev/api
But with the complete flow, to create an script that could make it work after doing something with puppeteer.
For example, i could make a previous request to log in, get the log in cookie form the request and provide it as an option to a callable unlighthouse.

I think this workaround will work for me.

But if you are instested in implementing a solution that works with the hook, i could make and provide you a basic example of the site.

Very thank you!

@AlEsGoGit
Copy link
Author

Hello again!
Are you interested in giving a solution to this?
As i said i could provide you a working sample site under a validation page.

If its the case ill need to know what will you need or what would be usefull for you to test and develop it.

Thank you!

@harlan-zw
Copy link
Owner

Hey, sorry for the lack of response.

I've released 0.10.0 which includes an authenticate hook which should make this easier.

See here: https://unlighthouse.dev/guide/guides/authentication#programmatic-usage

Let me know if you have any issues.

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

No branches or pull requests

2 participants