Skip to content

Commit

Permalink
feat(network intercept): populate "intercepts" in base event params
Browse files Browse the repository at this point in the history
Bug: #644
  • Loading branch information
Thiago Perrotta committed Oct 30, 2023
1 parent d7c613e commit 73bbe4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/bidiMapper/domains/network/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class NetworkManager {

request = new NetworkRequest(
id,
this.#networkStorage.eventManager,
this.#networkStorage,
this.#cdpTarget,
redirectCount
);
Expand Down
27 changes: 16 additions & 11 deletions src/bidiMapper/domains/network/NetworkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import type Protocol from 'devtools-protocol';

import {Deferred} from '../../../utils/Deferred.js';
import type {EventManager} from '../events/EventManager.js';
import {
Network,
type BrowsingContext,
Expand Down Expand Up @@ -52,7 +51,7 @@ export class NetworkRequest {
* The identifier for a request resulting from a redirect matches that of the
* request that initiated it.
*/
readonly requestId: Network.Request;
#requestId: Network.Request;

// TODO: Handle auth required?
/**
Expand All @@ -65,7 +64,7 @@ export class NetworkRequest {

#redirectCount: number;

#eventManager: EventManager;
#networkStorage: NetworkStorage;

#request: {
info?: Protocol.Network.RequestWillBeSentEvent;
Expand All @@ -86,16 +85,20 @@ export class NetworkRequest {

constructor(
requestId: Network.Request,
eventManager: EventManager,
networkStorage: NetworkStorage,
cdpTarget: CdpTarget,
redirectCount = 0
) {
this.requestId = requestId;
this.#eventManager = eventManager;
this.#requestId = requestId;
this.#networkStorage = networkStorage;
this.#cdpTarget = cdpTarget;
this.#redirectCount = redirectCount;
}

get requestId(): string {
return this.#requestId;
}

get url(): string | undefined {
return this.#response.info?.url ?? this.#request.info?.request.url;
}
Expand Down Expand Up @@ -206,7 +209,7 @@ export class NetworkRequest {
error: new Error('Network event loading failed'),
});

this.#eventManager.registerEvent(
this.#networkStorage.eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.Network.EventNames.FetchError,
Expand Down Expand Up @@ -394,8 +397,10 @@ export class NetworkRequest {
}

#getBaseEventParams(phase?: Network.InterceptPhase): Network.BaseParameters {
const isBlocked = phase !== undefined && phase === this.#interceptPhase; // TODO: Set this in terms of intercepts?

return {
isBlocked: phase !== undefined && phase === this.#interceptPhase,
isBlocked,
context: this.#context,
navigation: this.#getNavigationId(),
redirectCount: this.#redirectCount,
Expand Down Expand Up @@ -464,7 +469,7 @@ export class NetworkRequest {
if (this.#isIgnoredEvent()) {
return;
}
this.#eventManager.registerPromiseEvent(
this.#networkStorage.eventManager.registerPromiseEvent(
this.#beforeRequestSentDeferred.then((result) => {
if (result.kind === 'success') {
try {
Expand Down Expand Up @@ -508,7 +513,7 @@ export class NetworkRequest {
if (this.#isIgnoredEvent()) {
return;
}
this.#eventManager.registerPromiseEvent(
this.#networkStorage.eventManager.registerPromiseEvent(
this.#responseStartedDeferred.then((result) => {
if (result.kind === 'success') {
try {
Expand Down Expand Up @@ -579,7 +584,7 @@ export class NetworkRequest {
if (this.#isIgnoredEvent()) {
return;
}
this.#eventManager.registerPromiseEvent(
this.#networkStorage.eventManager.registerPromiseEvent(
this.#responseCompletedDeferred.then((result) => {
if (result.kind === 'success') {
try {
Expand Down

0 comments on commit 73bbe4b

Please sign in to comment.