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

Method unsubscribe

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

* Unsubscribe to events. See the note on subscribe above — this * cancels by event/context name, not by subscription id, so it can affect a * subscription this same connection made elsewhere. New code should call * the returned handle's `unsubscribe()` from addCallback inste

(events, browsingContexts)

Source from the content-addressed store, hash-verified

340 * @returns {Promise<void>}
341 */
342 async unsubscribe(events, browsingContexts) {
343 const eventsToRemove = typeof events === 'string' ? [events] : events
344
345 // Check if the eventsToRemove are in the subscribed events array
346 // Filter out events that are not in this.events before filtering
347 const existingEvents = eventsToRemove.filter((event) => this.events.includes(event))
348
349 // Remove the events from the subscribed events array
350 this.events = this.events.filter((event) => !existingEvents.includes(event))
351
352 if (typeof browsingContexts === 'string') {
353 this.browsingContexts.pop()
354 } else if (Array.isArray(browsingContexts)) {
355 this.browsingContexts = this.browsingContexts.filter((id) => !browsingContexts.includes(id))
356 }
357
358 if (existingEvents.length === 0) {
359 return
360 }
361 const params = {
362 method: 'session.unsubscribe',
363 params: {
364 events: existingEvents,
365 },
366 }
367
368 if (this.browsingContexts.length > 0) {
369 params.params.contexts = this.browsingContexts
370 }
371
372 await this.send(params)
373 }
374
375 /**
376 * Registers `handler` to be called on every delivered `method` event,

Callers 5

closeMethod · 0.45
closeMethod · 0.45
closeMethod · 0.45
closeMethod · 0.45
index_test.jsFile · 0.45

Calls 3

sendMethod · 0.95
filterMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected