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
|
```typescript
|
||||||
class Page {
|
class Page {
|
||||||
abstract authenticate(credentials: Credentials): Promise<void>;
|
abstract authenticate(credentials: Credentials | null): Promise<void>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ credentials
|
|||||||
|
|
||||||
</td><td>
|
</td><td>
|
||||||
|
|
||||||
[Credentials](./puppeteer.credentials.md)
|
[Credentials](./puppeteer.credentials.md) \| null
|
||||||
|
|
||||||
</td><td>
|
</td><td>
|
||||||
|
|
||||||
|
@ -1420,7 +1420,7 @@ export abstract class Page extends EventEmitter<PageEvents> {
|
|||||||
* @remarks
|
* @remarks
|
||||||
* To disable authentication, pass `null`.
|
* 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.
|
* 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;
|
#frameManager: FrameProvider;
|
||||||
#networkEventManager = new NetworkEventManager();
|
#networkEventManager = new NetworkEventManager();
|
||||||
#extraHTTPHeaders?: Record<string, string>;
|
#extraHTTPHeaders?: Record<string, string>;
|
||||||
#credentials?: Credentials;
|
#credentials: Credentials | null = null;
|
||||||
#attemptedAuthentications = new Set<string>();
|
#attemptedAuthentications = new Set<string>();
|
||||||
#userRequestInterceptionEnabled = false;
|
#userRequestInterceptionEnabled = false;
|
||||||
#protocolRequestInterceptionEnabled = false;
|
#protocolRequestInterceptionEnabled = false;
|
||||||
@ -121,7 +121,7 @@ export class NetworkManager extends EventEmitter<NetworkManagerEvents> {
|
|||||||
this.#clients.delete(client);
|
this.#clients.delete(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
async authenticate(credentials?: Credentials): Promise<void> {
|
async authenticate(credentials: Credentials | null): Promise<void> {
|
||||||
this.#credentials = credentials;
|
this.#credentials = credentials;
|
||||||
const enabled = this.#userRequestInterceptionEnabled || !!this.#credentials;
|
const enabled = this.#userRequestInterceptionEnabled || !!this.#credentials;
|
||||||
if (enabled === this.#protocolRequestInterceptionEnabled) {
|
if (enabled === this.#protocolRequestInterceptionEnabled) {
|
||||||
|
@ -743,7 +743,7 @@ export class CdpPage extends Page {
|
|||||||
this.#bindings.delete(name);
|
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);
|
return await this.#frameManager.networkManager.authenticate(credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,10 +751,7 @@ describe('network', function () {
|
|||||||
});
|
});
|
||||||
let response = (await page.goto(server.EMPTY_PAGE))!;
|
let response = (await page.goto(server.EMPTY_PAGE))!;
|
||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
await page.authenticate({
|
await page.authenticate(null);
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
});
|
|
||||||
// Navigate to a different origin to bust Chrome's credential caching.
|
// Navigate to a different origin to bust Chrome's credential caching.
|
||||||
try {
|
try {
|
||||||
response = (await page.goto(
|
response = (await page.goto(
|
||||||
|
Loading…
Reference in New Issue
Block a user