Skip to content

Commit 893e7e8

Browse files
committed
fix
1 parent e533990 commit 893e7e8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

packages/launcher/lib/linux/index.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,31 @@ const createTimeoutPromise = (timeout: number = 30000, message: string = `Timed
2121

2222
async function isFirefoxSnap (binary: string): Promise<boolean> {
2323
try {
24-
const binaryPath = await which(binary)
24+
const result = await Promise.race([getFirefoxSnap(binary), createTimeoutPromise(30000, 'Timed out after 30 seconds checking if Firefox is a snap')]) as Promise<boolean>
2525

26-
// if the bin path or what it's symlinked to start with `/snap/bin`, it's a snap
27-
if (binaryPath.startsWith('/snap/bin/') || (await fs.realpath(binaryPath)).startsWith('/snap/bin')) return true
28-
29-
// read the first 16kb, don't read the entire file into memory in case it is a binary
30-
const fd = await fs.open(binaryPath, 'r')
31-
const { buffer, bytesRead } = await fd.read<Buffer>({ length: 16384 })
32-
33-
await fd.close()
34-
35-
return buffer.slice(0, bytesRead).toString('utf8').includes('exec /snap/bin/firefox')
26+
return result
3627
} catch (err) {
3728
debug('failed to check if Firefox is a snap, assuming it isn\'t %o', { err, binary })
3829

3930
return false
4031
}
4132
}
4233

34+
async function getFirefoxSnap (binary: string): Promise<boolean> {
35+
const binaryPath = await which(binary)
36+
37+
// if the bin path or what it's symlinked to start with `/snap/bin`, it's a snap
38+
if (binaryPath.startsWith('/snap/bin/') || (await fs.realpath(binaryPath)).startsWith('/snap/bin')) return true
39+
40+
// read the first 16kb, don't read the entire file into memory in case it is a binary
41+
const fd = await fs.open(binaryPath, 'r')
42+
const { buffer, bytesRead } = await fd.read<Buffer>({ length: 16384 })
43+
44+
await fd.close()
45+
46+
return buffer.slice(0, bytesRead).toString('utf8').includes('exec /snap/bin/firefox')
47+
}
48+
4349
async function getLinuxBrowser (
4450
name: string,
4551
binary: string,
@@ -89,7 +95,7 @@ async function getLinuxBrowser (
8995
return
9096
}
9197

92-
if (name === 'firefox' && (await Promise.race([isFirefoxSnap(binary), createTimeoutPromise(30000, 'Timed out after 30 seconds checking if Firefox is a snap')]))) {
98+
if (name === 'firefox' && await isFirefoxSnap(binary)) {
9399
// if the binary in the path points to a script that calls the snap, set a snap-specific profile path
94100
// @see https://github.com/cypress-io/cypress/issues/19793
95101
debug('firefox is running as a snap, changing profile path')

0 commit comments

Comments
 (0)