Skip to content

Add 'window:*' events #2886

Closed
Closed
@chrisbreiding

Description

@chrisbreiding

Add a new event 'namespace' window:* where * is any event you can register on the window. So a user can do the following:

cy.on('window:hashchange', (e) => {})

This would bind to the window's hashchange event and be unbound after the test finishes running. It would rebind if the page navigates. Any arbitrary window event can be bound and receives the event as normally binding with window.addEventListener.

// instead of
cy.window().then((win) => {
  const handler = () => {
    // handling code
    win.removeEventListener('foobar', handler)
  }
  win.addEventListener('foobar', handler, false)
})

// the user can do this
cy.on('window:foobar', (e) => {
  // handling code
})

Metadata

Metadata

Assignees

Labels

pkg/driverThis is due to an issue in the packages/driver directorystage: ready for workThe issue is reproducible and in scopetype: enhancementRequested enhancement of existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions