Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/bidiMapper/BidiMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
export {BidiServer, MapperOptions} from './BidiServer.js';
export type {CdpConnection} from '../cdp/CdpConnection.js';
export type {CdpClient} from '../cdp/CdpClient.js';
export type {CdpClient, ExtendedCdpClient} from '../cdp/CdpClient.js';
export {EventEmitter} from '../utils/EventEmitter.js';
export type {BidiTransport} from './BidiTransport.js';
export {OutgoingMessage} from './OutgoingMessage.js';
Expand Down
28 changes: 18 additions & 10 deletions src/bidiMapper/modules/cdp/CdpTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
*/
import type {Protocol} from 'devtools-protocol';

import type {CdpClient} from '../../../cdp/CdpClient.js';
import {
type CdpClient,
type ExtendedCdpClient,
CdpClientWithEmulatedEventsWrapper,
} from '../../../cdp/CdpClient.js';
import {BiDiModule} from '../../../protocol/chromium-bidi.js';
import type {ChromiumBidi, Session} from '../../../protocol/protocol.js';
import {Deferred} from '../../../utils/Deferred.js';
Expand All @@ -41,6 +45,7 @@ interface FetchStages {
export class CdpTarget {
readonly #id: Protocol.Target.TargetID;
readonly #cdpClient: CdpClient;
readonly #extendedCdpClient: ExtendedCdpClient;
readonly #browserCdpClient: CdpClient;
readonly #parentCdpClient: CdpClient;
readonly #realmStorage: RealmStorage;
Expand Down Expand Up @@ -120,6 +125,7 @@ export class CdpTarget {
) {
this.#id = targetId;
this.#cdpClient = cdpClient;
this.#extendedCdpClient = new CdpClientWithEmulatedEventsWrapper(cdpClient);
this.#browserCdpClient = browserCdpClient;
this.#parentCdpClient = parentCdpClient;
this.#eventManager = eventManager;
Expand All @@ -141,8 +147,8 @@ export class CdpTarget {
return this.#id;
}

get cdpClient(): CdpClient {
return this.#cdpClient;
get cdpClient(): ExtendedCdpClient {
return this.#extendedCdpClient;
}

get parentCdpClient(): CdpClient {
Expand Down Expand Up @@ -192,7 +198,11 @@ export class CdpTarget {
// prerendered pages. Generic catch, as the error can vary between CdpClient
// implementations: Tab vs Puppeteer.
}),
this.toggleNetworkIfNeeded(),
// Enabling Network domain is required for navigation detection:
// https://github.com/GoogleChromeLabs/chromium-bidi/issues/2856.
this.#cdpClient
.sendCommand('Network.enable')
.then(() => this.toggleExtendedNetworkIfNeeded()),
this.#cdpClient.sendCommand('Target.setAutoAttach', {
autoAttach: true,
waitForDebuggerOnStart: true,
Expand Down Expand Up @@ -317,20 +327,18 @@ export class CdpTarget {
}

/**
* Toggles both Network and Fetch domains.
* Toggle Fetch domains and enable/disable network cache.
*/
async toggleNetworkIfNeeded(): Promise<void> {
const enabled = this.isSubscribedTo(BiDiModule.Network);
async toggleExtendedNetworkIfNeeded(): Promise<void> {
const enabled = true;
if (enabled === this.#networkDomainEnabled) {
return;
}

this.#networkDomainEnabled = enabled;
try {
await Promise.all([
this.#cdpClient
.sendCommand(enabled ? 'Network.enable' : 'Network.disable')
.then(async () => await this.toggleSetCacheDisabled()),
this.toggleSetCacheDisabled(),
this.toggleFetchIfNeeded(),
]);
} catch (err) {
Expand Down
Loading