
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
playwright-lighthouse
Advanced tools
Lighthouse is a tool developed by Google that analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.
Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.
The purpose of this package is to produce web audit report for several pages in connected mode and in an automated (programmatic) way.
You can have to add the playwright-lighthouse
library as a dependency (or dev-dependency) in your project
$ yarn add -D playwright-lighthouse
# or
$ npm install --save-dev playwright-lighthouse
After completion of the Installation, you can use playwright-lighthouse
in your code to audit the current page.
In your test code you need to import playwright-lighthouse
and assign a port
for the lighthouse scan. You can choose any non-allocated port.
const { playAudit } = require('playwright-lighthouse');
const playwright = require('playwright');
describe('audit example', () => {
it('open browser', async () => {
const browser = await playwright['chromium'].launch({
args: ['--remote-debugging-port=9222'],
});
const page = await browser.newPage();
await page.goto('https://angular.io/');
await playAudit({
page: page,
port: 9222,
});
await browser.close();
});
});
If you don't provide any threshold argument to the playAudit
command, the test will fail if at least one of your metrics is under 100
.
You can make assumptions on the different metrics by passing an object as argument to the playAudit
command:
const { playAudit } = require('playwright-lighthouse');
const playwright = require('playwright');
describe('audit example', () => {
it('open browser', async () => {
const browser = await playwright['chromium'].launch({
args: ['--remote-debugging-port=9222'],
});
const page = await browser.newPage();
await page.goto('https://angular.io/');
await playAudit({
page: page,
thresholds: {
performance: 50,
accessibility: 50,
'best-practices': 50,
seo: 50,
pwa: 50,
},
port: 9222,
});
await browser.close();
});
});
If the Lighthouse analysis returns scores that are under the one set in arguments, the test will fail.
You can also make assumptions only on certain metrics. For example, the following test will only verify the "correctness" of the performance
metric:
await playAudit({
page: page,
thresholds: {
performance: 85,
},
port: 9222,
});
This test will fail only when the performance
metric provided by Lighthouse will be under 85
.
You can also pass any argument directly to the Lighthouse module using the second and third options of the command:
const thresholdsConfig = {
/* ... */
};
const lighthouseOptions = {
/* ... your lighthouse options */
};
const lighthouseConfig = {
/* ... your lighthouse configs */
};
await playAudit({
thresholds: thresholdsConfig,
opts: lighthouseOptions,
config: lighthouseConfig,
/* ... other configurations */
});
playwright-lighthouse
library can produce very famous Lighthouse HTML audit report, that you can host in your CI server. This report is really necessary to check the detailed report.
await playAudit({
/* ... other configurations */
htmlReport: true, //defaults to false
reportDir: `path/to/directory`, //defaults to `${process.cwd()}/lighthouse`
reportName: `name-of-the-report`, //defaults to `lighthouse-${new Date().getTime()}.html`
});
This will result in below HTML report
you can raise any issue here
If it works for you , give a Star! :star:
- Copyright © 2020- Abhinaba Ghosh
FAQs
Playwright Lighthouse Audit
The npm package playwright-lighthouse receives a total of 70,523 weekly downloads. As such, playwright-lighthouse popularity was classified as popular.
We found that playwright-lighthouse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.