Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/webpage-impact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The follwing config parameters are optional:
- `headers`:
- `accept`: string https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept
- `accept-encoding`: array of allowed encodings (a single encoding can also be passed as a string) https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
- `username`: The plugin supports simple logins with username and password. Provide the username if the page you want to measure requires such a login. The password needs to be stored in a shell environment variable called `WI_PASSWORD`. Please note, that the login may fail nevertheless because the plugin expects a certain interface that may not be provided by your page.

### Returns

Expand Down
18 changes: 17 additions & 1 deletion src/lib/webpage-impact/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type WebpageImpactOptions = {
reload: boolean;
cacheEnabled: boolean;
scrollToBottom?: boolean;
username?: string;
};

type ResourceBase = {
Expand Down Expand Up @@ -176,6 +177,7 @@ const WebpageImpactUtils = () => {
reload: false,
cacheEnabled: false,
scrollToBottom: config?.scrollToBottom,
username: config?.username,
});

let reloadedResources: Resource[] | undefined;
Expand Down Expand Up @@ -203,7 +205,7 @@ const WebpageImpactUtils = () => {
const loadPageResources = async (
page: Page,
url: string,
{reload, cacheEnabled, scrollToBottom}: WebpageImpactOptions
{reload, cacheEnabled, scrollToBottom, username}: WebpageImpactOptions
): Promise<Resource[]> => {
try {
await page.setCacheEnabled(cacheEnabled);
Expand Down Expand Up @@ -254,6 +256,20 @@ const WebpageImpactUtils = () => {

if (!reload) {
await page.goto(url, {waitUntil: 'networkidle0'});
if (username !== undefined) {
const password = process.env.WI_PASSWORD;
if (password === undefined) {
throw new Error(
`${LOGGER_PREFIX}: Username but no password provided. Store password in environment variable 'WI_PASSWORD'.`
);
}
await page.type('#username', username);
await page.type('#password', password);

await page.click('#submit');

await page.waitForNavigation();
}
} else {
await page.reload({waitUntil: 'networkidle0'});
}
Expand Down