MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / BrowsingContext

Class BrowsingContext

javascript/selenium-webdriver/bidi/browsingContext.js:102–597  ·  view source on GitHub ↗

* Represents the contains under BrowsingContext module commands. * Described in https://w3c.github.io/webdriver-bidi/#module-browsingContext * Each browsing context command requires a browsing context id. * Hence, this class represent browsing context lifecycle.

Source from the content-addressed store, hash-verified

100 * Hence, this class represent browsing context lifecycle.
101 */
102class BrowsingContext {
103 constructor(driver) {
104 this._driver = driver
105 }
106
107 /**
108 * @returns id
109 */
110 get id() {
111 return this._id
112 }
113
114 async init({ browsingContextId = undefined, type = undefined, createParameters = undefined }) {
115 if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
116 throw Error('WebDriver instance must support BiDi protocol')
117 }
118
119 if (browsingContextId === undefined && type === undefined && createParameters === undefined) {
120 throw Error('Either BrowsingContextId or Type or CreateParameters must be provided')
121 }
122
123 if (type === undefined && createParameters !== undefined) {
124 throw Error('Type must be provided with CreateParameters')
125 }
126
127 if (type !== undefined && !['window', 'tab'].includes(type)) {
128 throw Error(`Valid types are 'window' & 'tab'. Received: ${type}`)
129 }
130
131 this.bidi = await this._driver.getBidi()
132 this._id =
133 browsingContextId === undefined
134 ? (await this.create(type, createParameters))['result']['context']
135 : browsingContextId
136 }
137
138 /**
139 * Creates a browsing context for the given type with the given parameters
140 */
141 async create(type, createParameters = undefined) {
142 if (createParameters !== undefined && (!createParameters) instanceof CreateContextParameters) {
143 throw Error(`Pass in the instance of CreateContextParameters. Received: ${createParameters}`)
144 }
145
146 let parameters = new Map()
147 parameters.set('type', type)
148
149 if (createParameters !== undefined) {
150 createParameters.asMap().forEach((value, key) => {
151 parameters.set(key, value)
152 })
153 }
154
155 const params = {
156 method: 'browsingContext.create',
157 params: Object.fromEntries(parameters),
158 }
159 return await this.bidi.send(params)

Callers 8

network_test.jsFile · 0.50
bidi_test.jsFile · 0.50
storage_test.jsFile · 0.50
script_test.jsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected