I’m working with Puppeteer and running into an issue where videos start downloading automatically instead of showing in a browser player. Here’s my current code:
When I run this script, Chrome starts downloading the video file right away instead of displaying it in the built-in video player. I want the video to play in the browser like it normally would. Is there a way to configure Puppeteer or set some browser options to prevent this automatic download behavior and make it show the video player instead?
The issue occurs because Chrome defaults to downloading mp4 files directly rather than playing them inline. You need to intercept the request and modify the response headers to force browser playback. Use page.setRequestInterception(true) and handle the response to set Content-Type: video/mp4 and add Content-Disposition: inline header. Alternatively, create an HTML wrapper page with a video element pointing to your mp4 source - this guarantees the browser treats it as embedded media rather than a downloadable file. I’ve encountered this exact problem before and the header modification approach works consistently across different video formats.
try adding ‘–disable-web-security’ and ‘–allow-running-insecure-content’ to your args array. also you might need to set user agent since some sites block headless browsers even when headless is false. worked for me when i had similiar issue
I ran into something similar when scraping media content last month. The problem is that you’re navigating directly to the mp4 file URL, which triggers the browser’s default download behavior. Instead of trying to modify headers or add flags, I found it much easier to create a temporary HTML page with a video tag. You can either generate a local HTML file with <video controls><source src="your-url" type="video/mp4"></video> and navigate to that, or use page.setContent() to inject the HTML directly. This approach mimics how videos are normally embedded on websites and Chrome will display the native video player controls automatically. Much cleaner than wrestling with response headers.