MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / subscribe

Method subscribe

javascript/selenium-webdriver/bidi/index.js:237–273  ·  view source on GitHub ↗

* Subscribe to events * @param events * @param browsingContexts * @returns {Promise }

(events, browsingContexts)

Source from the content-addressed store, hash-verified

235 * @returns {Promise<void>}
236 */
237 async subscribe(events, browsingContexts) {
238 function toArray(arg) {
239 if (arg === undefined) {
240 return []
241 }
242
243 return Array.isArray(arg) ? [...arg] : [arg]
244 }
245
246 const eventsArray = toArray(events)
247 const contextsArray = toArray(browsingContexts)
248
249 const params = {
250 method: 'session.subscribe',
251 params: {},
252 }
253
254 if (eventsArray.length && eventsArray.some((event) => typeof event !== 'string')) {
255 throw new TypeError('events should be string or string array')
256 }
257
258 if (contextsArray.length && contextsArray.some((context) => typeof context !== 'string')) {
259 throw new TypeError('browsingContexts should be string or string array')
260 }
261
262 if (eventsArray.length) {
263 params.params.events = eventsArray
264 }
265
266 if (contextsArray.length) {
267 params.params.contexts = contextsArray
268 }
269
270 this.events.push(...eventsArray)
271
272 await this.send(params)
273 }
274
275 /**
276 * Unsubscribe to events

Callers 8

initMethod · 0.80
UnboundZmqEventBusMethod · 0.80
_subscribe_to_eventFunction · 0.80
subscribe_to_eventMethod · 0.80

Calls 2

sendMethod · 0.95
toArrayFunction · 0.85

Tested by

no test coverage detected