HTTP requests blocked in headless browser due to mixed content warnings

I’m working with a headless browser setup using Playwright and running into mixed content issues. My application needs to make HTTP requests instead of HTTPS because I have a reverse proxy configuration in my container that maps the external hostname to localhost.

When my headless browser tries to call my API endpoints, I keep getting blocked with an error message like this:

Mixed Content: The page at 'https://dashboard.myservice.com/' was loaded over HTTPS, but requested an insecure resource 'http://dashboard.myservice.com/api/[email protected]'. This request has been blocked; the content must be served over HTTPS

I need to force all requests to use HTTP protocol due to my proxy setup. What’s the best way to handle this mixed content restriction in Playwright?

To resolve the mixed content issue in Playwright, you can launch your browser with the --disable-web-security and --allow-running-insecure-content flags. I encountered similar challenges with proxy configurations in containers, and these flags effectively circumvented the restrictions. However, exercise caution as these adjustments compromise security. For production environments, it’s crucial to configure your reverse proxy to manage SSL termination correctly.

try using the ignoreHTTPSErrors option when you set up your browser context. it helps in skipping mixed content warnings. also, look into your playwright config for any settings that could be blocking http requests.

You can bypass mixed content restrictions by configuring Playwright’s browser context with specific permissions. Add --disable-features=VizDisplayCompositor and --unsafely-treat-insecure-origin-as-secure=http://dashboard.myservice.com flags to your launchOptions. This whitelists your domain for insecure content instead of killing all security checks. I’ve dealt with this in Docker setups where internal routing needed HTTP but external used HTTPS. Just make sure your reverse proxy handles the protocol translation properly at the container level.