()
| 90 | */ |
| 91 | // fallow-ignore-next-line complexity |
| 92 | export async function resolveChromeExecutablePath(): Promise<string> { |
| 93 | const source = resolveChromeSource(); |
| 94 | if (source === "sparticuz") { |
| 95 | const mod = await loadSparticuzChromium(); |
| 96 | const path = await mod.executablePath(); |
| 97 | // Guard against the wedge described in ChromeBinaryUnavailableError. |
| 98 | // sparticuz's contract is "return the path to a usable binary" — when |
| 99 | // it returns null/undefined/"" we can't hand that to puppeteer-core |
| 100 | // (which will throw an unrelated-looking assertion). Same when the |
| 101 | // returned path doesn't exist (extraction failed but the function |
| 102 | // call returned). |
| 103 | if (!path || typeof path !== "string") { |
| 104 | throw new ChromeBinaryUnavailableError(source, null, SPARTICUZ_WEDGE_HINT); |
| 105 | } |
| 106 | if (!existsSync(path)) { |
| 107 | throw new ChromeBinaryUnavailableError(source, path, SPARTICUZ_WEDGE_HINT); |
| 108 | } |
| 109 | return path; |
| 110 | } |
| 111 | const explicit = process.env.HYPERFRAMES_LAMBDA_CHROME_PATH; |
| 112 | if (!explicit) { |
| 113 | throw new ChromeBinaryUnavailableError( |
| 114 | source, |
| 115 | null, |
| 116 | "HYPERFRAMES_LAMBDA_CHROME_SOURCE=chrome-headless-shell requires " + |
| 117 | "HYPERFRAMES_LAMBDA_CHROME_PATH to be set to the absolute path of the bundled binary.", |
| 118 | ); |
| 119 | } |
| 120 | if (!existsSync(explicit)) { |
| 121 | throw new ChromeBinaryUnavailableError( |
| 122 | source, |
| 123 | explicit, |
| 124 | `HYPERFRAMES_LAMBDA_CHROME_PATH=${JSON.stringify(explicit)} does not exist on disk.`, |
| 125 | ); |
| 126 | } |
| 127 | return explicit; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Resolve the Chromium launch args for the selected source. For |
no test coverage detected