UNPKG

selenium-webdriver

Version:

The official WebDriver JavaScript bindings from the Selenium project

108 lines (107 loc) 3.85 kB
"use strict"; // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The SFC licenses this file // to you 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. Object.defineProperty(exports, "__esModule", { value: true }); exports.Browser = void 0; exports.getBrowserInstance = getBrowserInstance; // --- Additional Types --- /** @deprecated Use {@link Browser.create} instead — will be removed in a future major version. */ async function getBrowserInstance(driver) { return Browser.create(driver); } // --- Implementation --- class Browser { constructor(bidi) { this.bidi = bidi; } static async create(driver) { const caps = await driver.getCapabilities(); if (!caps.get('webSocketUrl')) { throw new Error('WebDriver instance must support BiDi protocol'); } const bidi = await driver.getBidi(); return new Browser(bidi); } async close() { const response = await this.bidi.send({ method: 'browser.close', params: {}, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } } async createUserContext(params) { const response = await this.bidi.send({ method: 'browser.createUserContext', params: params, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } return response.result; } async getClientWindows() { const response = await this.bidi.send({ method: 'browser.getClientWindows', params: {}, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } return response.result; } async getUserContexts() { const response = await this.bidi.send({ method: 'browser.getUserContexts', params: {}, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } return response.result; } async removeUserContext(params) { const response = await this.bidi.send({ method: 'browser.removeUserContext', params: params, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } } async setClientWindowState(params) { const response = await this.bidi.send({ method: 'browser.setClientWindowState', params: params, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } return response.result; } async setDownloadBehavior(params) { const response = await this.bidi.send({ method: 'browser.setDownloadBehavior', params: params, }); if (response['type'] === 'error') { throw new Error(`${response['error']}: ${response['message']}`); } } } exports.Browser = Browser;