Path: blob/trunk/javascript/selenium-webdriver/bidi/urlPattern.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 URL pattern to intercept.19* Described in network.UrlPatternPattern https://w3c.github.io/webdriver-bidi/#type-network-UrlPattern20*/21class UrlPattern {22#map = new Map()2324/**25* Sets the protocol for the URL pattern.26*27* @param {string} protocol - The protocol to set.28* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.29*/30protocol(protocol) {31this.#map.set('protocol', protocol)32return this33}3435/**36* Sets the hostname for the URL pattern.37*38* @param {string} hostname - The hostname to set.39* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.40*/41hostname(hostname) {42this.#map.set('hostname', hostname)43return this44}4546/**47* Sets the port for the URL pattern.48*49* @param {number} port - The port number to set.50* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.51* @throws {Error} - Throws an error if the port is not a number.52*/53port(port) {54if (typeof port === 'number') {55this.#map.set('port', port.toString())56} else {57throw new Error(`Port must be a number. Received:'${port}'`)58}59return this60}6162/**63* Sets the pathname for the URL pattern.64*65* @param {string} pathname - The pathname to set.66* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.67*/68pathname(pathname) {69this.#map.set('pathname', pathname)70return this71}7273/**74* Sets the search parameter in the URL pattern.75*76* @param {string} search - The search parameter to be set.77* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.78*/79search(search) {80this.#map.set('search', search)81return this82}8384asMap() {85this.#map.set('type', 'pattern')86return this.#map87}88}8990module.exports = { UrlPattern }919293