Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/bidi/urlPattern.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* Represents a URL pattern to intercept.
20
* Described in network.UrlPatternPattern https://w3c.github.io/webdriver-bidi/#type-network-UrlPattern
21
*/
22
class UrlPattern {
23
#map = new Map()
24
25
/**
26
* Sets the protocol for the URL pattern.
27
*
28
* @param {string} protocol - The protocol to set.
29
* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.
30
*/
31
protocol(protocol) {
32
this.#map.set('protocol', protocol)
33
return this
34
}
35
36
/**
37
* Sets the hostname for the URL pattern.
38
*
39
* @param {string} hostname - The hostname to set.
40
* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.
41
*/
42
hostname(hostname) {
43
this.#map.set('hostname', hostname)
44
return this
45
}
46
47
/**
48
* Sets the port for the URL pattern.
49
*
50
* @param {number} port - The port number to set.
51
* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.
52
* @throws {Error} - Throws an error if the port is not a number.
53
*/
54
port(port) {
55
if (typeof port === 'number') {
56
this.#map.set('port', port.toString())
57
} else {
58
throw new Error(`Port must be a number. Received:'${port}'`)
59
}
60
return this
61
}
62
63
/**
64
* Sets the pathname for the URL pattern.
65
*
66
* @param {string} pathname - The pathname to set.
67
* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.
68
*/
69
pathname(pathname) {
70
this.#map.set('pathname', pathname)
71
return this
72
}
73
74
/**
75
* Sets the search parameter in the URL pattern.
76
*
77
* @param {string} search - The search parameter to be set.
78
* @returns {UrlPattern} - Returns the updated instance of the URL pattern for chaining.
79
*/
80
search(search) {
81
this.#map.set('search', search)
82
return this
83
}
84
85
asMap() {
86
this.#map.set('type', 'pattern')
87
return this.#map
88
}
89
}
90
91
module.exports = { UrlPattern }
92
93