Skip to content

Commit

Permalink
skip iframe load logic if page is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed Dec 9, 2021
1 parent 7a696a6 commit b9154f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
24 changes: 0 additions & 24 deletions packages/driver/cypress/integration/commands/navigation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1440,30 +1440,6 @@ describe('src/cy/commands/navigation', () => {
})

it('throws attempting to visit 2 unique ip addresses', function (done) {
const $autIframe = cy.state('$autIframe')

const load = () => {
return $autIframe.trigger('load')
}

cy.stub(Cypress, 'backend')
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
isHtml: true,
url: 'http://127.0.0.1:3500',
})

// whenever we're told to change the src
// just fire the load event directly on the $autIframe
cy.stub(Cypress.utils, 'iframeSrc').callsFake(load)

// make it seem like we're already on http://127.0.0.1:3500
const one = Cypress.Location.create('http://127.0.0.1:3500/fixtures/generic.html')

cy.stub(Cypress.utils, 'locExisting')
.returns(one)

cy.on('fail', (err) => {
const { lastLog } = this

Expand Down
10 changes: 10 additions & 0 deletions packages/driver/src/cypress/cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ export class $Cy implements ITimeouts, IStability, IAssertions, IRetries, IJQuer
// proxy has not injected Cypress.action('window:before:load')
// so Cypress.onBeforeAppWindowLoad() was never called
return $autIframe.on('load', () => {
if (state('isStable')) {
// Chromium 97+ triggers fires iframe onload for cross-origin-initiated same-document
// navigations to make it appear to be a cross-document navigation, even when it wasn't
// to alleviate security risk where a cross-origin initiator can check whether
// or not onload fired to guess the url of a target frame.
// When the onload is fired, neither the before:unload or unload event is fired to remove
// the attached listeners or to clean up the current page state.
return
}

// if setting these props failed
// then we know we're in a cross origin failure
try {
Expand Down

0 comments on commit b9154f5

Please sign in to comment.