GoogleChrome / GoogleChrome/lighthouse

Lighthouse may end with an unhandled rejection due to an invalid URL

Open
#13,956 4 comments 0 reactions 1 assignee Claimed by @paulirish View on GitHub
bug P3
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 14h
Merged PRs (30d)
20

Description

### FAQ

- [X] Yes, my issue is not about [variability](https://github.com/GoogleChrome/lighthouse/blob/master/docs/variability.md) or [throttling](https://github.com/GoogleChrome/lighthouse/blob/master/docs/throttling.md).
- [X] Yes, my issue is not about a specific accessibility audit (file with [axe-core](https://github.com/dequelabs/axe-core) instead).

### URL

https://www.salesforce.com/au/editions-pricing/quip/%00

### What happened?

Using the following pattern:

```js
try {
await lighthouse(url, {});
} catch (lhError) {
//
}
```

An unhandled rejection is thrown (eventually caught by a listener on `unhandledRejection` in `process`):

```
Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
at Function.fromProtocolMessage (/.../node_modules/lighthouse/lighthouse-core/lib/lh-error.js:148:19)
at /.../node_modules/lighthouse/lighthouse-core/gather/connections/connection.js:141:25
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
protocolMethod: 'Page.navigate',
protocolError: 'Cannot navigate to invalid URL'
}
```

Then, once timeout is reached (I believe), I receive this same error as `lhError`.

### What did you expect?

No unhandled promise or run stuck until the timeout.

Whether it should return an `LHError` error instead with an `INVALID_URL` code I can't really tell.

### What have you tried?

Ran lighthouse CLI using the latest version:

> lighthouse --version
> 9.5.0

> lighthouse "https://www.salesforce.com/au/editions-pricing/quip/%00" --skip-audits --disable-storage-reset

And got:

```
LH:status Preparing network conditions +1ms
LH:status Beginning devtoolsLog and trace +14ms
LH:status Loading page & waiting for onload +83ms
LH:status Navigating to https://www.salesforce.com/au/editions-pricing/quip/%00 +0ms
LH:method <= browser ERR:error Page.navigate +5ms
Unhandled Rejection. Reason: Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
LH:ChromeLauncher Killing Chrome instance 67680 +1ms
```

Whereas an invalid URL (ex: starting with 'htp://') would end with:

```
LH:ChromeLauncher Waiting for browser... +0ms
LH:ChromeLauncher Waiting for browser..... +510ms
LH:ChromeLauncher Waiting for browser.....✓ +1ms
LH:ChromeLauncher Killing Chrome instance 67742 +942ms
Runtime error encountered: The URL you have provided appears to be invalid.
LHError: INVALID_URL
at Function.normalizeUrl (/Users/anthony/.nvm/versions/node/v14.17.3/lib/node_modules/lighthouse/lighthouse-core/lib/url-shim.js:263:13)
at /Users/anthony/.nvm/versions/node/v14.17.3/lib/node_modules/lighthouse/lighthouse-core/index.js:51:30
at Function.gather (/Users/anthony/.nvm/versions/node/v14.17.3/lib/node_modules/lighthouse/lighthouse-core/runner.js:170:27)
at lighthouse (/Users/anthony/.nvm/versions/node/v14.17.3/lib/node_modules/lighthouse/lighthouse-core/index.js:50:34)
at runLighthouse (file:///Users/anthony/.nvm/versions/node/v14.17.3/lib/node_modules/lighthouse/lighthouse-cli/run.js:252:14)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
```

### How were you running Lighthouse?

node

### Lighthouse Version

9.5.0

### Chrome Version

_No response_

### Node Version

14.17.3

### OS

Mac

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.