-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Using lighthouse programmatically in typescript fails #15124
Comments
I'll check if this error occurs using a version prior to the refactor with ES Modules from #12689 |
Did the port change in earlier versions from late 2022 like 9.6.8 or 9.6.7? I got past the ES Modules error in the most recent version with both of those prior versions, but get the following error from both:
|
Did you try The error message you give suggests that your test file is being transpiled to commonjs before running, I think. You did a dynamic import and that should have worked, yet the error message says you didn't. What's your test runner? |
Thanks @connorjclark , that got me past the module error to a new one below. I had seen another thread that suggested to use the port "8041" to connect to the Playwright port on Chromium. *I know this isn't the Playwright project or the right place for support, but am curious to know if the lighthouse experts already know what to do here...
|
There was an example provided in this comment: However, I'm using the "@playwright/test" dependency which is an abstraction over "playwright", which the example uses. As a result, I configured playwright with the chromium flag to specify the debug port that lighthouse can use reliably. This configuration uses the same solution outlined in a Playwright issue comment about how to set chromium flags.
But, continue to get the error:
|
And, also tried this suggestion: Setting the environment variable prior to running the tests... |
@connorjclark et al, I added a debug call to the chromium debug endpoint by adding the below to the test.
... and getting the output...
💥 But, the lighthouse connection still fails with:
|
Update with extra info: We can run the CLI against an already running URL. But, we are hoping to integrate this into an automated test. Without the above Playwright integration working, we'll look into automating the |
Great news @connorjclark ! We got this working: |
FAQ
URL
https://demo.playwright.dev/todomvc
What happened?
Following the general instructions to use lighthouse programmatically...
... in a TypeScript project with Playwright tests...
... with both a top-level import of lighthouse as well as trying a dynamic import ...
... the test begins, but fails with an ES Module import error.
What did you expect?
Either version of the
import
syntax to "just work".What have you tried?
import lighthouse from 'lighthouse';
const lighthouse = await import('lighthouse');
playwright test
seemed confused)MY_PROJECT_PATH/tests/performance.spec.ts
How were you running Lighthouse?
node, Other
Lighthouse Version
10.2.0
Chrome Version
"@playwright/test": "^1.34.3",
Node Version
v18.16.0
OS
Windows 11 Pro, 22H2
Relevant log output
The text was updated successfully, but these errors were encountered: