mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: providing null to page.authenticate should disable authentication (#12203)
This commit is contained in:
parent
97a4951d52
commit
f375267e79
@ -10,7 +10,7 @@ Provide credentials for `HTTP authentication`.
|
||||
|
||||
```typescript
|
||||
class Page {
|
||||
abstract authenticate(credentials: Credentials): Promise<void>;
|
||||
abstract authenticate(credentials: Credentials | null): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
@ -35,7 +35,7 @@ credentials
|
||||
|
||||
</td><td>
|
||||
|
||||
[Credentials](./puppeteer.credentials.md)
|
||||
[Credentials](./puppeteer.credentials.md) \| null
|
||||
|
||||
</td><td>
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ export abstract class Page extends EventEmitter<PageEvents> {
|
||||
* @remarks
|
||||
* To disable authentication, pass `null`.
|
||||
*/
|
||||
abstract authenticate(credentials: Credentials): Promise<void>;
|
||||
abstract authenticate(credentials: Credentials | null): Promise<void>;
|
||||
|
||||
/**
|
||||
* The extra HTTP headers will be sent with every request the page initiates.
|
||||
|
@ -64,7 +64,7 @@ export class NetworkManager extends EventEmitter<NetworkManagerEvents> {
|
||||
#frameManager: FrameProvider;
|
||||
#networkEventManager = new NetworkEventManager();
|
||||
#extraHTTPHeaders?: Record<string, string>;
|
||||
#credentials?: Credentials;
|
||||
#credentials: Credentials | null = null;
|
||||
#attemptedAuthentications = new Set<string>();
|
||||
#userRequestInterceptionEnabled = false;
|
||||
#protocolRequestInterceptionEnabled = false;
|
||||
@ -121,7 +121,7 @@ export class NetworkManager extends EventEmitter<NetworkManagerEvents> {
|
||||
this.#clients.delete(client);
|
||||
}
|
||||
|
||||
async authenticate(credentials?: Credentials): Promise<void> {
|
||||
async authenticate(credentials: Credentials | null): Promise<void> {
|
||||
this.#credentials = credentials;
|
||||
const enabled = this.#userRequestInterceptionEnabled || !!this.#credentials;
|
||||
if (enabled === this.#protocolRequestInterceptionEnabled) {
|
||||
|
@ -743,7 +743,7 @@ export class CdpPage extends Page {
|
||||
this.#bindings.delete(name);
|
||||
}
|
||||
|
||||
override async authenticate(credentials: Credentials): Promise<void> {
|
||||
override async authenticate(credentials: Credentials | null): Promise<void> {
|
||||
return await this.#frameManager.networkManager.authenticate(credentials);
|
||||
}
|
||||
|
||||
|
@ -751,10 +751,7 @@ describe('network', function () {
|
||||
});
|
||||
let response = (await page.goto(server.EMPTY_PAGE))!;
|
||||
expect(response.status()).toBe(200);
|
||||
await page.authenticate({
|
||||
username: '',
|
||||
password: '',
|
||||
});
|
||||
await page.authenticate(null);
|
||||
// Navigate to a different origin to bust Chrome's credential caching.
|
||||
try {
|
||||
response = (await page.goto(
|
||||
|
Loading…
Reference in New Issue
Block a user