Path: blob/trunk/javascript/selenium-webdriver/bidi/createContextParameters.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* Represents a set of parameters for creating a context.19* Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-create.20*/21class CreateContextParameters {22#map = new Map()2324/**25* Sets the reference context.26* @param {string} id - The ID of the reference context.27* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.28* @throws {Error} - If the provided ID is not a string.29*/30referenceContext(id) {31if (typeof id !== 'string') {32throw new Error(`ReferenceContext must be string. Received:'${id}'`)33}34this.#map.set('referenceContext', id)35return this36}3738/**39* Sets the background parameter.40*41* @param {boolean} background - The background value to set.42* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.43* @throws {Error} - If the background parameter is not a boolean.44*/45background(background) {46if (typeof background !== 'boolean') {47throw new Error(`Background must be boolean. Received:'${background}'`)48}49this.#map.set('background', background)50return this51}5253/**54* Sets the user context.55* @param {string} userContext - The user context to set.56* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.57* @throws {Error} - If the userContext parameter is not a string.58*/59userContext(userContext) {60if (typeof userContext !== 'string') {61throw new Error(`UserContext must be string. Received:'${userContext}'`)62}63this.#map.set('userContext', userContext)64return this65}6667asMap() {68return this.#map69}70}7172module.exports = { CreateContextParameters }737475