Skip to content

Commit ebbf7b1

Browse files
fix: do not use unload events in Chromium from App Runner (#30061)
* correctly determine current browser family from cy config in app event manager * changelog * rm unnecessary ts-ignore * add type declaration to catch improper params to isBrowserFamily * add check for msMatchesSelector so jquery does not add unload listener in chrome add check for msMatchesSelector in jquery patch so unload is only added in ie * run windows workflow on this branch --------- Co-authored-by: Jennifer Shehane <[email protected]>
1 parent 06acc2e commit ebbf7b1

File tree

9 files changed

+21
-15
lines changed

9 files changed

+21
-15
lines changed

.circleci/workflows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ windowsWorkflowFilters: &windows-workflow-filters
7676
- equal: [ develop, << pipeline.git.branch >> ]
7777
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
7878
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
79-
- equal: [ 'fix/8599', << pipeline.git.branch >> ]
79+
- equal: [ 'cacie/29880/unload-in-chromium', << pipeline.git.branch >> ]
8080
- matches:
8181
pattern: /^release\/\d+\.\d+\.\d+$/
8282
value: << pipeline.git.branch >>

cli/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ _Released 8/27/2024 (PENDING)_
2020

2121
- Fixed an issue where files outside the Cypress project directory were not calculating the bundle output path correctly for the `file:preprocessor`. Addresses [#8599](https://github.com/cypress-io/cypress/issues/8599).
2222

23+
**Bugfixes:**
24+
25+
- Correctly determines current browser family when choosing between `unload` and `pagehide` options in App Runner. Fixes [#29880](https://github.com/cypress-io/cypress/issues/29880).
26+
2327
**Dependency Updates:**
2428

2529
- Updated `detect-port` from `1.3.0` to `1.6.1`. Addressed in [#30038](https://github.com/cypress-io/cypress/pull/30038).

packages/app/src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { injectBundle } from './runner/injectBundle'
1010
import { createPinia } from './store'
1111
import Toast, { POSITION } from 'vue-toastification'
1212
import 'vue-toastification/dist/index.css'
13-
import { createWebsocket, getRunnerConfigFromWindow } from './runner'
13+
import { createWebsocket } from './runner'
14+
import { getRunnerConfigFromWindow } from './runner/get-runner-config-from-window'
1415
import { telemetry } from '@packages/telemetry/src/browser'
1516

1617
// Grab the time just before loading config to include that in the cypress:app span

packages/app/src/runner/event-manager.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { handlePausing } from './events/pausing'
1616
import { addTelemetryListeners } from './events/telemetry'
1717
import { telemetry } from '@packages/telemetry/src/browser'
1818
import { addCaptureProtocolListeners } from './events/capture-protocol'
19+
import { getRunnerConfigFromWindow } from './get-runner-config-from-window'
1920

2021
export type CypressInCypressMochaEvent = Array<Array<string | Record<string, any>>>
2122

@@ -347,7 +348,7 @@ export class EventManager {
347348
// While we must move to pagehide for Chromium, it does not work for our
348349
// needs in Firefox. Until that is addressed, only Chromium uses the pagehide
349350
// event as a proxy for AUT unloads.
350-
const unloadEvent = this.isBrowser({ family: 'chromium' }) ? 'pagehide' : 'unload'
351+
const unloadEvent = this.isBrowserFamily('chromium') ? 'pagehide' : 'unload'
351352

352353
$window.on(unloadEvent, (e) => {
353354
this._clearAllCookies()
@@ -400,10 +401,8 @@ export class EventManager {
400401
this._addListeners()
401402
}
402403

403-
isBrowser (browserName) {
404-
if (!this.Cypress) return false
405-
406-
return this.Cypress.isBrowser(browserName)
404+
isBrowserFamily (family: string) {
405+
return getRunnerConfigFromWindow()?.browser?.family === family
407406
}
408407

409408
initialize ($autIframe: JQuery<HTMLIFrameElement>, config: Record<string, any>) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { decodeBase64Unicode } from '@packages/frontend-shared/src/utils/base64'
2+
3+
export function getRunnerConfigFromWindow () {
4+
return JSON.parse(decodeBase64Unicode(window.__CYPRESS_CONFIG__?.base64Config)) as Cypress.Config
5+
}

packages/app/src/runner/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import { IframeModel } from './iframe-model'
2323
import { AutIframe } from './aut-iframe'
2424
import { EventManager } from './event-manager'
2525
import { createWebsocket as createWebsocketIo } from '@packages/socket/lib/browser'
26-
import { decodeBase64Unicode } from '@packages/frontend-shared/src/utils/base64'
2726
import type { AutomationElementId } from '@packages/types'
2827
import { useSnapshotStore } from './snapshot-store'
2928
import { useStudioStore } from '../store/studio-store'
29+
import { getRunnerConfigFromWindow } from './get-runner-config-from-window'
3030

3131
let _eventManager: EventManager | undefined
3232

@@ -343,10 +343,6 @@ function runSpecE2E (config, spec: SpecFile) {
343343
getEventManager().initialize($autIframe, config)
344344
}
345345

346-
export function getRunnerConfigFromWindow () {
347-
return JSON.parse(decodeBase64Unicode(window.__CYPRESS_CONFIG__.base64Config)) as Cypress.Config
348-
}
349-
350346
/**
351347
* Inject the global `UnifiedRunner` via a <script src="..."> tag.
352348
* which includes the event manager and AutIframe constructor.

packages/app/src/runner/reporter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getMobxRunnerStore, MobxRunnerStore, useSpecStore } from '../store'
22
import { getReporterElement } from './utils'
3-
import { getEventManager, getRunnerConfigFromWindow } from '.'
3+
import { getEventManager } from '.'
4+
import { getRunnerConfigFromWindow } from './get-runner-config-from-window'
45
import type { EventManager } from './event-manager'
56
import { useRunnerUiStore } from '../store/runner-ui-store'
67

packages/app/src/specs/tree/useCollapsibleTree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from 'vue'
22
import { computed } from 'vue'
33
import { useToggle } from '@vueuse/core'
44
import type { FoundSpec } from '@packages/types/src'
5-
import { getRunnerConfigFromWindow } from '../../runner'
5+
import { getRunnerConfigFromWindow } from '../../runner/get-runner-config-from-window'
66

77
export type RawNode <T> = {
88
id: string

packages/driver/patches/jquery+3.4.1.dev.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ index 773ad95..84ca2f6 100644
8989
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
9090
+ // two documents; shallow comparisons work.
9191
+ // eslint-disable-next-line eqeqeq
92-
+ if ( preferredDoc != document &&
92+
+ if ( docElem.msMatchesSelector && preferredDoc != document &&
9393
+ ( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {
9494

9595
- // Support: IE 11, Edge

0 commit comments

Comments
 (0)