Running Puppeteer in a Docker container can sometimes lead to unexpected errors, especially when interacting with the headless browser. One such error is the “ProtocolError: Network.enable timed out” message, which occurs when trying to get a new browser page using Puppeteer in a Docker environment. This issue can be particularly frustrating, but it’s often related to the browser’s inability to start properly within the container.
Thank me by sharing on Twitter 🙏
Error Description
The exact error message you may encounter looks like this:
ProtocolError: Network.enable timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.
This error typically occurs during the execution of await browser.newPage()
in your Puppeteer script, preventing you from successfully launching a new page in the browser.
Cause of the Error
The root cause of this error is likely that the Chrome executable is not starting properly within the Docker container. This can be due to a variety of factors, including resource constraints, missing dependencies, or the specific configuration of the Docker environment.
Solution
The solution that worked for me involved adding the --disable-gpu
flag to the Puppeteer launch options. Disabling GPU acceleration in a Docker environment can resolve issues related to Chrome’s startup, particularly when GPU resources are unavailable or unnecessary.
Elebase USB to USB C Adapter 4 Pack,USBC Female to A Male Car Charger,Type C Converter for iPhone 16 16e Pro Max,15 14 13 12 Plus,Apple Watch,Airpods,Compatible for Nintendo Switch,Samsung Galaxy S25
$8.09 (as of March 31, 2025 14:14 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)The Scaling Era: An Oral History of AI, 2019–2025
$32.55 (as of March 31, 2025 14:14 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)iPhone Charger 3 Pack 10 ft Apple MFi Certified Lightning Nylon Braided Cable Fast Charging Cord Compatible with iPhone 13 12 11 Pro Max XR XS X 8 7 6 Plus SE iPad and More
$9.99 (as of March 31, 2025 14:14 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Here’s a step-by-step guide to resolving this error:
- Modify Your Puppeteer Launch Configuration: In your TypeScript Puppeteer script, update the
launch
configuration to include the--disable-gpu
flag:
import puppeteer, { Browser } from 'puppeteer';
async function runPuppeteer(): Promise<void> {
const browser: Browser = await puppeteer.launch({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || '/usr/bin/chromium-browser',
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-gpu', // Disable GPU acceleration
],
protocolTimeout: 120000, // Optional: Increase the protocol timeout if needed
});
const page = await browser.newPage();
await page.goto('https://example.com');
// Your code here
await browser.close();
}
runPuppeteer().catch(error => {
console.error('Error running Puppeteer:', error);
});
- Rebuild and Run Your Docker Container: Make sure to rebuild your Docker image and rerun the container to apply the changes:
docker build -t my-puppeteer-app .
docker run my-puppeteer-app
- Alternative Fixes:
While the--disable-gpu
flag resolved the issue in this case, there could be other potential fixes, such as:
- Increasing the container’s CPU and memory limits.
- Ensuring all necessary dependencies for Chromium are installed.
- Using the
--no-sandbox
and--disable-setuid-sandbox
flags, which are commonly required in Docker environments.
Verification
After applying the fix, you can verify that the error has been resolved by running your Puppeteer script again. If successful, Puppeteer should no longer time out when opening a new page, and the script will proceed as expected.
Conclusion
Disabling GPU acceleration with the --disable-gpu
flag is a practical solution when running Puppeteer inside a Docker container. This fix addresses issues related to the browser’s startup and can prevent the frustrating “ProtocolError: Network.enable timed out” error. It’s a simple yet effective way to ensure that your Puppeteer scripts run smoothly in a containerized environment.
Tags/Keywords: Puppeteer, Docker, ProtocolError, Network.enable timed out, Chromium, Puppeteer in Docker, Headless Browser, Node.js, TypeScript
This TypeScript-based blog post should help others facing similar issues with Puppeteer in Docker containers.
What a lifesaver! Thank you for this amazing post.