Skip to content

Commit

Permalink
chore: fix auth event
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Feb 23, 2024
1 parent cd77a8f commit 5f9c76c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
11 changes: 6 additions & 5 deletions src/bidiMapper/domains/network/NetworkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class NetworkRequest {
);

const requestInterceptionCompleted =
(requestInterceptionExpected && Boolean(this.#request.paused)) ||
!requestInterceptionExpected;
!requestInterceptionExpected ||
(requestInterceptionExpected && Boolean(this.#request.paused));

if (
Boolean(this.#request.info) &&
Expand All @@ -194,8 +194,8 @@ export class NetworkRequest {
);

const responseInterceptionCompleted =
(responseInterceptionExpected && Boolean(this.#response.paused)) ||
!responseInterceptionExpected;
!responseInterceptionExpected ||
(responseInterceptionExpected && Boolean(this.#response.paused));

if (
this.#response.info ||
Expand Down Expand Up @@ -291,7 +291,8 @@ export class NetworkRequest {
}
}

onAuthRequired(_event: Protocol.Fetch.AuthRequiredEvent) {
onAuthRequired(event: Protocol.Fetch.AuthRequiredEvent) {
this.#fetchId = event.requestId;
this.#interceptPhase = Network.InterceptPhase.AuthRequired;
if (!this.blocked) {
void this.continueWithAuth();
Expand Down
13 changes: 11 additions & 2 deletions src/bidiMapper/domains/network/NetworkStorage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ describe('NetworkStorage', () => {
eventManager = new EventManager(browsingContextStorage);
processingQueue = new ProcessingQueue<OutgoingMessage>(
async ({message}) => {
const cdpEvent = message as unknown as ChromiumBidi.Event;
processedEvents.set(cdpEvent.method, cdpEvent.params);
if (message.type === 'event') {
processedEvents.set(message.method, message.params);
}
return await Promise.resolve();
},
logger
Expand Down Expand Up @@ -537,5 +538,13 @@ describe('NetworkStorage', () => {
expect(event).to.exist;
request.requestWillBeSent();
});

it('should work with only authRequired', async () => {
const request = new MockCdpNetworkEvents(cdpClient);

request.authRequired();
const event = await getEvent('network.authRequired');
expect(event).to.exist;
});
});
});
16 changes: 2 additions & 14 deletions src/bidiMapper/domains/network/NetworkStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,21 +322,9 @@ export class NetworkStorage {
cdpTarget: CdpTarget
) {
// CDP quirk if the Network domain is not present this is undefined
const request = this.getRequestByFetchId(event.requestId);
let request = this.getRequestByFetchId(event.requestId);
if (!request) {
// CDP quirk even both request/response may be continued
// with this command
void cdpTarget.cdpClient
.sendCommand('Fetch.continueWithAuth', {
requestId: event.requestId,
authChallengeResponse: {
response: 'Default',
},
})
.catch(() => {
// TODO: add logging
});
return;
request = this.#getOrCreateNetworkRequest(event.requestId, cdpTarget);
}

request.onAuthRequired(event);
Expand Down
6 changes: 1 addition & 5 deletions src/protocol/chromium-bidi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ export type ResultData = WebDriverBidi.ResultData | Cdp.ResultData;

export type BidiPlusChannel = string | null;

export type Message = (
| WebDriverBidi.Message
| Cdp.Message
| {launched: true}
) & {
export type Message = (WebDriverBidi.Message | Cdp.Message) & {
channel?: BidiPlusChannel;
};

0 comments on commit 5f9c76c

Please sign in to comment.