@@ -28,54 +28,26 @@ export const runLighthouse = async (url, settings) => {
28
28
try {
29
29
console . log ( 'Launching Chrome with puppeteer...' ) ;
30
30
31
- // Set cache directory before any Puppeteer operations
32
- process . env . PUPPETEER_CACHE_DIR = '/tmp/puppeteer' ;
33
- console . log ( 'Setting Puppeteer cache directory:' , process . env . PUPPETEER_CACHE_DIR ) ;
31
+ // Set Puppeteer browser path to a writable location
32
+ const browserPath = '/tmp/puppeteer/chrome/linux-136.0.7103.92/chrome-linux64/chrome' ;
33
+ process . env . PUPPETEER_BROWSER_PATH = browserPath ;
34
+ console . log ( 'Setting Puppeteer browser path:' , process . env . PUPPETEER_BROWSER_PATH ) ;
34
35
36
+ // Create the directory structure if it doesn't exist
35
37
try {
36
- console . log ( 'Installing Chrome...' ) ;
37
- await puppeteer . browsers ( ) . install ( ) ;
38
- console . log ( 'Chrome installation complete' ) ;
38
+ await fs . promises . mkdir ( '/tmp/puppeteer/chrome/linux-136.0.7103.92/chrome-linux64' , { recursive : true } ) ;
39
+ console . log ( 'Browser directory structure created' ) ;
39
40
} catch ( err ) {
40
- console . log ( 'Error installing Chrome :' , err . message ) ;
41
+ console . error ( 'Error creating browser directory :' , err . message ) ;
41
42
}
42
43
43
- // Check for Chrome in Netlify environment first
44
- const chromePaths = [
45
- '/opt/buildhome/.cache/puppeteer/chrome/linux-136.0.7103.92/chrome-linux64/chrome' ,
46
- '/opt/buildhome/.cache/puppeteer/chrome/linux-119.0.6045.105/chrome-linux64/chrome' ,
47
- '/usr/bin/google-chrome' ,
48
- '/usr/bin/chromium-browser'
49
- ] ;
50
-
51
- let executablePath ;
52
- for ( const path of chromePaths ) {
53
- try {
54
- await fs . promises . access ( path ) ;
55
- executablePath = path ;
56
- console . log ( 'Found Chrome at:' , path ) ;
57
- break ;
58
- } catch ( err ) {
59
- console . log ( `Chrome not found at ${ path } ` ) ;
60
- }
61
- }
62
-
63
- if ( ! executablePath ) {
64
- console . log ( 'No Chrome installation found, using bundled Chromium' ) ;
65
- // Let puppeteer use its bundled version
66
- executablePath = undefined ;
67
- }
68
-
69
- // Use /tmp directory which should be writable in Netlify
70
- const cacheDirectory = '/tmp/puppeteer' ;
71
- console . log ( 'Using cache directory:' , cacheDirectory ) ;
72
-
73
- // Ensure cache directory exists
44
+ // Verify the browser path exists
74
45
try {
75
- await fs . promises . mkdir ( cacheDirectory , { recursive : true } ) ;
76
- console . log ( 'Cache directory created/verified' ) ;
46
+ await fs . promises . access ( browserPath ) ;
47
+ console . log ( 'Browser exists at:' , browserPath ) ;
48
+ launchOptions . chromePath = browserPath ;
77
49
} catch ( err ) {
78
- console . warn ( 'Could not create cache directory:' , err . message ) ;
50
+ console . log ( 'Browser not found at configured path, will use default' ) ;
79
51
}
80
52
81
53
// Launch browser for Lighthouse with specific configuration for Netlify
@@ -94,23 +66,11 @@ export const runLighthouse = async (url, settings) => {
94
66
} ;
95
67
96
68
console . log ( 'Launching browser with config:' , launchConfig ) ;
97
-
98
- console . log ( 'Final launch config:' , launchConfig ) ;
99
69
browser = await puppeteer . launch ( launchConfig ) ;
100
-
101
- // Get browser information
102
70
console . log ( 'Browser launched successfully' ) ;
103
71
104
72
const wsEndpoint = browser . wsEndpoint ( ) ;
105
73
console . log ( 'Browser WebSocket endpoint:' , wsEndpoint ) ;
106
-
107
- // Use the launch config's executable path for chrome-launcher
108
- if ( launchConfig . executablePath ) {
109
- console . log ( `Using Chrome at: ${ launchConfig . executablePath } ` ) ;
110
- launchOptions . chromePath = launchConfig . executablePath ;
111
- } else {
112
- console . log ( 'Using default Chrome path' ) ;
113
- }
114
74
} finally {
115
75
if ( browser ) {
116
76
try {
@@ -123,7 +83,6 @@ export const runLighthouse = async (url, settings) => {
123
83
}
124
84
} catch ( error ) {
125
85
console . error ( 'Error launching Chrome with puppeteer:' , error ) ;
126
- throw error ;
127
86
}
128
87
129
88
chrome = await chromeLauncher . launch ( launchOptions ) ;
0 commit comments