Jan 15, 2025
0
Level 1
BrowserShot (Puppeteer) issue
[Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX' }
here is my code:
try { $tempaPath = 'temp/' . uniqid() . '.png'; $tempFilePath = Storage::path($tempaPath);
// Ensure the 'puppeteer' directory inside 'temp' exists
$puppeteerDir = storage_path('app/temp/puppeteer');
if (!Storage::exists('temp/puppeteer')) {
Storage::makeDirectory('temp/puppeteer', 0777, true); // Make directory with permissions
}
// Use Browsershot to capture the screenshot
Browsershot::url('https:// example.com')
->setNodeBinary('D:/laragon/bin/nodejs/node-v18/node.exe') // Ensure Node.js binary path is correct
->setOption('args', ['--no-sandbox', '--disable-setuid-sandbox'])
->setOption('userDataDir', $puppeteerDir) // Set the correct userDataDir
->save($tempFilePath);
// Success: Return the path of the saved image
return $tempaPath;
} catch (\Exception $e) {
// Log the error message
Log::error('Error while capturing screenshot: ' . $e->getMessage());
Log::info('User data directory: ' . $puppeteerDir);
}
Please or to participate in this conversation.