chromium-bidi
Version:
An implementation of the WebDriver BiDi protocol for Chromium implemented as a JavaScript layer translating between BiDi and CDP, running inside a Chrome tab.
114 lines • 4.75 kB
JavaScript
/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InvalidArgumentException, } from '../../../protocol/protocol.js';
export class SessionProcessor {
constructor(eventManager, browserCdpClient, initConnection) {
this.
this.
this.
}
status() {
return { ready: false, message: 'already connected' };
}
// Roughly following https://www.w3.org/TR/webdriver2/#dfn-capabilities-processing.
// Validations should already be done by the parser.
const mergedCapabilities = [];
for (const first of capabilitiesRequest.firstMatch ?? [{}]) {
const result = {
...capabilitiesRequest.alwaysMatch,
};
for (const key of Object.keys(first)) {
if (result[key] !== undefined) {
throw new InvalidArgumentException(`Capability ${key} in firstMatch is already defined in alwaysMatch`);
}
result[key] = first[key];
}
mergedCapabilities.push(result);
}
const match = mergedCapabilities.find((c) => c.browserName === 'chrome') ??
mergedCapabilities[0] ??
{};
match.unhandledPromptBehavior = this.
return match;
}
if (capabilityValue === undefined) {
return undefined;
}
if (typeof capabilityValue === 'object') {
// Do not validate capabilities. Incorrect ones will be ignored by Mapper.
return capabilityValue;
}
if (typeof capabilityValue !== 'string') {
throw new InvalidArgumentException(`Unexpected 'unhandledPromptBehavior' type: ${typeof capabilityValue}`);
}
switch (capabilityValue) {
case 'accept':
case 'accept and notify':
return { default: "accept" /* Session.UserPromptHandlerType.Accept */ };
case 'dismiss':
case 'dismiss and notify':
return { default: "dismiss" /* Session.UserPromptHandlerType.Dismiss */ };
case 'ignore':
return { default: "ignore" /* Session.UserPromptHandlerType.Ignore */ };
default:
throw new InvalidArgumentException(`Unexpected 'unhandledPromptBehavior' value: ${capabilityValue}`);
}
}
async new(params) {
if (this.
throw new Error('Session has been already created.');
}
this.
const matchedCapabitlites = this.
await this.
const version = await this.
return {
sessionId: 'unknown',
capabilities: {
...matchedCapabitlites,
acceptInsecureCerts: matchedCapabitlites.acceptInsecureCerts ?? false,
browserName: version.product,
browserVersion: version.revision,
platformName: '',
setWindowRect: false,
webSocketUrl: '',
userAgent: version.userAgent,
},
};
}
async subscribe(params, channel = {}) {
const subscription = await this.
return {
subscription,
};
}
async unsubscribe(params, channel = {}) {
if ('subscriptions' in params) {
await this.
return {};
}
await this.
return {};
}
}
//# sourceMappingURL=SessionProcessor.js.map