From 97b72e8056987029e566daef44b0ca1addb47231 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 25 Mar 2024 18:31:00 +0100 Subject: [PATCH] feat: implement readonly capabilities --- src/bidiMapper/CommandProcessor.ts | 8 ++++-- .../domains/session/SessionProcessor.ts | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/bidiMapper/CommandProcessor.ts b/src/bidiMapper/CommandProcessor.ts index df595affc8..229e63e086 100644 --- a/src/bidiMapper/CommandProcessor.ts +++ b/src/bidiMapper/CommandProcessor.ts @@ -133,7 +133,10 @@ export class CommandProcessor extends EventEmitter { preloadScriptStorage, logger ); - this.#sessionProcessor = new SessionProcessor(eventManager); + this.#sessionProcessor = new SessionProcessor( + eventManager, + browserCdpClient + ); this.#storageProcessor = new StorageProcessor( browserCdpClient, browsingContextStorage, @@ -147,7 +150,6 @@ export class CommandProcessor extends EventEmitter { ): Promise { switch (command.method) { case 'session.end': - case 'session.new': // TODO: Implement. break; @@ -325,6 +327,8 @@ export class CommandProcessor extends EventEmitter { // Session domain // keep-sorted start block=yes + case 'session.new': + return await this.#sessionProcessor.create(command.params); case 'session.status': return this.#sessionProcessor.status(); case 'session.subscribe': diff --git a/src/bidiMapper/domains/session/SessionProcessor.ts b/src/bidiMapper/domains/session/SessionProcessor.ts index 883b87ea3a..ad33cde19c 100644 --- a/src/bidiMapper/domains/session/SessionProcessor.ts +++ b/src/bidiMapper/domains/session/SessionProcessor.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import type {CdpClient} from '../../../cdp/CdpClient.js'; import type {BidiPlusChannel} from '../../../protocol/chromium-bidi.js'; import type { ChromiumBidi, @@ -26,15 +27,38 @@ import type {EventManager} from './EventManager.js'; export class SessionProcessor { #eventManager: EventManager; + #browserCdpClient: CdpClient; - constructor(eventManager: EventManager) { + constructor(eventManager: EventManager, browserCdpClient: CdpClient) { this.#eventManager = eventManager; + this.#browserCdpClient = browserCdpClient; } status(): Session.StatusResult { return {ready: false, message: 'already connected'}; } + async create(_params: Session.NewParameters): Promise { + // Since mapper exists, there is a session already. + // Still the mapper can handle capabilities for us. + // Currently, only Puppeteer calls here but, eventually, every client + // should delegrate capability processing here. + const version = + await this.#browserCdpClient.sendCommand('Browser.getVersion'); + return { + sessionId: 'unknown', + capabilities: { + acceptInsecureCerts: false, + browserName: version.product, + browserVersion: version.revision, + platformName: '', + setWindowRect: false, + webSocketUrl: '', + userAgent: version.userAgent, + }, + }; + } + async subscribe( params: Session.SubscriptionRequest, channel: BidiPlusChannel = null