Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: providing null to page.authenticate should disable authentication #12203

Merged
merged 3 commits into from
May 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions docs/api/puppeteer.page.authenticate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
```

Expand All @@ -35,7 +35,7 @@ credentials

</td><td>

[Credentials](./puppeteer.credentials.md)
[Credentials](./puppeteer.credentials.md) \| null

</td><td>

Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/api/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/cdp/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/cdp/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 1 addition & 4 deletions test/src/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading