Skip to content

Commit 58b40f5

Browse files
authored
Revert "fix: use stdio for CDP instead of TCP (#14348)"
This reverts commit 148a3e1.
1 parent c3dc7f4 commit 58b40f5

File tree

10 files changed

+100
-365
lines changed

10 files changed

+100
-365
lines changed

packages/launcher/lib/browsers.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export function launch (
9797
browser: FoundBrowser,
9898
url: string,
9999
args: string[] = [],
100-
opts: { pipeStdio?: boolean } = {},
101100
) {
102101
log('launching browser %o', { browser, url })
103102

@@ -111,15 +110,7 @@ export function launch (
111110

112111
log('spawning browser with args %o', { args })
113112

114-
const stdio = ['ignore', 'pipe', 'pipe']
115-
116-
if (opts.pipeStdio) {
117-
// also pipe stdio 3 and 4 for access to debugger protocol
118-
stdio.push('pipe', 'pipe')
119-
}
120-
121-
// @ts-ignore
122-
const proc = cp.spawn(browser.path, args, { stdio })
113+
const proc = cp.spawn(browser.path, args, { stdio: ['ignore', 'pipe', 'pipe'] })
123114

124115
proc.stdout.on('data', (buf) => {
125116
log('%s stdout: %s', browser.name, String(buf).trim())
Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports['e2e cdp / with TCP transport / handles disconnections as expected'] = `
1+
exports['e2e cdp / handles disconnections as expected'] = `
22
33
====================================================================================================
44
@@ -59,67 +59,4 @@ Error: connect ECONNREFUSED 127.0.0.1:7777
5959
✖ 1 of 1 failed (100%) XX:XX - - 1 - -
6060
6161
62-
`
63-
64-
exports['e2e cdp / with stdio transport / falls back to connecting via tcp when stdio cannot be connected'] = `
65-
66-
====================================================================================================
67-
68-
(Run Starting)
69-
70-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
71-
│ Cypress: 1.2.3 │
72-
│ Browser: FooBrowser 88 │
73-
│ Specs: 1 found (spec.ts) │
74-
│ Searched: cypress/integration/spec.ts │
75-
└────────────────────────────────────────────────────────────────────────────────────────────────┘
76-
77-
78-
────────────────────────────────────────────────────────────────────────────────────────────────────
79-
80-
Running: spec.ts (1 of 1)
81-
Warning: Cypress failed to connect to Chrome via stdio after 1 second. Falling back to TCP...
82-
Connecting to Chrome via TCP was successful, continuing with tests.
83-
84-
85-
passes
86-
✓ passes
87-
88-
89-
1 passing
90-
91-
92-
(Results)
93-
94-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
95-
│ Tests: 1 │
96-
│ Passing: 1 │
97-
│ Failing: 0 │
98-
│ Pending: 0 │
99-
│ Skipped: 0 │
100-
│ Screenshots: 0 │
101-
│ Video: true │
102-
│ Duration: X seconds │
103-
│ Spec Ran: spec.ts │
104-
└────────────────────────────────────────────────────────────────────────────────────────────────┘
105-
106-
107-
(Video)
108-
109-
- Started processing: Compressing to 32 CRF
110-
- Finished processing: /XXX/XXX/XXX/cypress/videos/spec.ts.mp4 (X second)
111-
112-
113-
====================================================================================================
114-
115-
(Run Finished)
116-
117-
118-
Spec Tests Passing Failing Pending Skipped
119-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
120-
│ ✔ spec.ts XX:XX 1 1 - - - │
121-
└────────────────────────────────────────────────────────────────────────────────────────────────┘
122-
✔ All specs passed! XX:XX 1 1 - - -
123-
124-
125-
`
62+
`

packages/server/lib/browsers/chrome.ts

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import * as CriClient from './cri-client'
1515
import * as protocol from './protocol'
1616
import utils from './utils'
1717
import { Browser } from './types'
18-
import errors from '../errors'
1918

2019
// TODO: this is defined in `cypress-npm-api` but there is currently no way to get there
2120
type CypressConfiguration = any
@@ -38,9 +37,6 @@ type ChromePreferences = {
3837
localState: object
3938
}
4039

41-
const staticCdpPort = Number(process.env.CYPRESS_REMOTE_DEBUGGING_PORT)
42-
const stdioTimeoutMs = Number(process.env.CYPRESS_CDP_TARGET_TIMEOUT) || 60000
43-
4440
const pathToExtension = extension.getPathToExtension()
4541
const pathToTheme = extension.getPathToTheme()
4642

@@ -177,7 +173,9 @@ const _writeChromePreferences = (userDir: string, originalPrefs: ChromePreferenc
177173
}
178174

179175
const getRemoteDebuggingPort = async () => {
180-
return staticCdpPort || utils.getPort()
176+
const port = Number(process.env.CYPRESS_REMOTE_DEBUGGING_PORT)
177+
178+
return port || utils.getPort()
181179
}
182180

183181
/**
@@ -245,47 +243,19 @@ const _disableRestorePagesPrompt = function (userDir) {
245243
.catch(() => { })
246244
}
247245

248-
const useStdioCdp = (browser) => {
249-
return (
250-
// CDP via stdio doesn't seem to work in browsers older than 72
251-
// @see https://github.com/cyrus-and/chrome-remote-interface/issues/381#issuecomment-445277683
252-
browser.majorVersion >= 72
253-
// allow users to force TCP by specifying a port in environment
254-
&& !staticCdpPort
255-
)
256-
}
257-
258246
// After the browser has been opened, we can connect to
259247
// its remote interface via a websocket.
260-
const _connectToChromeRemoteInterface = function (browser, process, port, onError) {
261-
const connectTcp = () => {
262-
// @ts-ignore
263-
la(check.userPort(port), 'expected port number to connect CRI to', port)
264-
265-
debug('connecting to Chrome remote interface at random port %d', port)
266-
267-
return protocol.getWsTargetFor(port)
268-
.then((wsUrl) => {
269-
debug('received wsUrl %s for port %d', wsUrl, port)
270-
271-
return CriClient.create({ target: wsUrl }, onError)
272-
})
273-
}
274-
275-
if (!useStdioCdp(browser)) {
276-
return connectTcp()
277-
}
278-
279-
return CriClient.create({ process }, onError)
280-
.timeout(stdioTimeoutMs)
281-
.catch(Bluebird.TimeoutError, async () => {
282-
errors.warning('CDP_STDIO_TIMEOUT', browser.displayName, stdioTimeoutMs)
248+
const _connectToChromeRemoteInterface = function (port, onError) {
249+
// @ts-ignore
250+
la(check.userPort(port), 'expected port number to connect CRI to', port)
283251

284-
const client = await connectTcp()
252+
debug('connecting to Chrome remote interface at random port %d', port)
285253

286-
errors.warning('CDP_FALLBACK_SUCCEEDED', browser.displayName)
254+
return protocol.getWsTargetFor(port)
255+
.then((wsUrl) => {
256+
debug('received wsUrl %s for port %d', wsUrl, port)
287257

288-
return client
258+
return CriClient.create(wsUrl, onError)
289259
})
290260
}
291261

@@ -465,10 +435,6 @@ export = {
465435
args.push(`--remote-debugging-port=${port}`)
466436
args.push('--remote-debugging-address=127.0.0.1')
467437

468-
if (useStdioCdp(browser)) {
469-
args.push('--remote-debugging-pipe')
470-
}
471-
472438
return args
473439
},
474440

@@ -524,16 +490,14 @@ export = {
524490
// first allows us to connect the remote interface,
525491
// start video recording and then
526492
// we will load the actual page
527-
const launchedBrowser = await utils.launch(browser, 'about:blank', args, {
528-
pipeStdio: useStdioCdp(browser),
529-
})
493+
const launchedBrowser = await utils.launch(browser, 'about:blank', args)
530494

531495
la(launchedBrowser, 'did not get launched browser instance')
532496

533497
// SECOND connect to the Chrome remote interface
534498
// and when the connection is ready
535499
// navigate to the actual url
536-
const criClient = await this._connectToChromeRemoteInterface(browser, launchedBrowser, port, options.onError)
500+
const criClient = await this._connectToChromeRemoteInterface(port, options.onError)
537501

538502
la(criClient, 'expected Chrome remote interface reference', criClient)
539503

0 commit comments

Comments
 (0)