* Ensures Chromium browser binary is installed before running accessibility audits. * * Uses Node's module resolution and npm's bin specification to locate playwright-core CLI, * working reliably with all package managers (npm, pnpm, yarn).
()
| 112 | * working reliably with all package managers (npm, pnpm, yarn). |
| 113 | */ |
| 114 | private async installBrowser(): Promise<void> { |
| 115 | if (this.browserInstalled) { |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | logger.debug('Checking Chromium browser installation ...'); |
| 120 | |
| 121 | const require = createRequire(import.meta.url); |
| 122 | const pkgPath = require.resolve('playwright-core/package.json'); |
| 123 | const pkg = require(pkgPath); |
| 124 | const cliPath = path.join( |
| 125 | path.dirname(pkgPath), |
| 126 | pkg.bin['playwright-core'], |
| 127 | ); |
| 128 | |
| 129 | await executeProcess({ |
| 130 | command: 'node', |
| 131 | args: [cliPath, 'install', 'chromium'], |
| 132 | }); |
| 133 | |
| 134 | this.browserInstalled = true; |
| 135 | } |
| 136 | |
| 137 | /** Lazily launches or returns existing Chromium browser instance. */ |
| 138 | private async launchBrowser(): Promise<Browser> { |
no test coverage detected