Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/bidi/realmInfo.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 the types of realms.
20
* Described in https://w3c.github.io/webdriver-bidi/#type-script-RealmType.
21
* @enum
22
*/
23
const RealmType = {
24
AUDIO_WORKLET: 'audio-worklet',
25
DEDICATED_WORKER: 'dedicated-worker',
26
PAINT_WORKLET: 'paint-worklet',
27
SERVICE_WORKED: 'service-worker',
28
SHARED_WORKED: 'shared-worker',
29
WINDOW: 'window',
30
WORKER: 'worker',
31
WORKLET: 'worklet',
32
33
findByName(name) {
34
return (
35
Object.values(this).find((type) => {
36
return typeof type === 'string' && name.toLowerCase() === type.toLowerCase()
37
}) || null
38
)
39
},
40
}
41
42
/**
43
* Represents information about a realm.
44
* Described in https://w3c.github.io/webdriver-bidi/#type-script-RealmInfo.
45
*/
46
class RealmInfo {
47
/**
48
* Constructs a new RealmInfo object.
49
* @param {string} realmId - The ID of the realm.
50
* @param {string} origin - The origin of the realm.
51
* @param {string} realmType - The type of the realm.
52
*/
53
constructor(realmId, origin, realmType) {
54
this.realmId = realmId
55
this.origin = origin
56
this.realmType = realmType
57
}
58
59
static fromJson(input) {
60
let realmId = null
61
let origin = null
62
let realmType = null
63
let browsingContext = null
64
let sandbox = null
65
66
if ('type' in input) {
67
let typeString = input['type']
68
realmType = RealmType.findByName(typeString)
69
}
70
71
if ('realm' in input) {
72
realmId = input['realm']
73
}
74
75
if ('origin' in input) {
76
origin = input['origin']
77
}
78
79
if ('context' in input) {
80
browsingContext = input['context']
81
}
82
83
if ('sandbox' in input) {
84
sandbox = input['sandbox']
85
}
86
87
if (realmType === RealmType.WINDOW) {
88
return new WindowRealmInfo(realmId, origin, realmType, browsingContext, sandbox)
89
}
90
91
return new RealmInfo(realmId, origin, realmType)
92
}
93
}
94
95
/**
96
* Represents information about a window realm.
97
* @extends RealmInfo
98
*/
99
class WindowRealmInfo extends RealmInfo {
100
/**
101
* Constructs a new instance of the WindowRealmInfo class.
102
* @param {string} realmId - The ID of the realm.
103
* @param {string} origin - The origin of the realm.
104
* @param {string} realmType - The type of the realm.
105
* @param {string} browsingContext - The browsing context of the realm.
106
* @param {string|null} sandbox - The sandbox of the realm (optional).
107
*/
108
constructor(realmId, origin, realmType, browsingContext, sandbox = null) {
109
super(realmId, origin, realmType)
110
this.browsingContext = browsingContext
111
this.sandbox = sandbox
112
}
113
}
114
115
module.exports = {
116
RealmInfo,
117
RealmType,
118
WindowRealmInfo,
119
}
120
121