How to Disable 'Block Insecure Private Network Requests' in Chrome for Playwright Codegen
Tired of Chrome blocking your private network requests during Playwright Codegen testing? This guide provides a step-by-step solution to disable the "Block insecure private network requests" feature, ensuring your forms submit as expected.
The Problem: Unexpected Blocking
Google Chrome's "Block insecure private network requests" feature, designed to enhance security, can sometimes interfere with local development and testing. When enabled, it prevents requests from secure contexts (HTTPS) to insecure private network resources (HTTP). This can manifest as forms failing to submit or unexpected pop-ups.
Solution: Disabling the Feature
Here's how to consistently disable this feature for Playwright Codegen:
Step 1: Configure Chrome Flags
- Open Google Chrome and navigate to
chrome://flags/#block-insecure-private-network-requests
. - Search for "Block insecure private network requests".
- Set the dropdown menu to "Disabled".
- Restart Chrome completely for the changes to take effect. Ensure all Chrome processes are closed.
Step 2: Verify the Setting
- After restarting Chrome, revisit
chrome://flags/#block-insecure-private-network-requests
to confirm the setting is indeed "Disabled."
Step 3: Configure Playwright (Option A - Recommended):
To avoid relying solely on global Chrome settings, configure Playwright directly. Modify your Playwright configuration file (e.g., playwright.config.ts
or playwright.config.js
) to include launch arguments that disable the feature.
This method ensures the setting is applied specifically to the Playwright-launched browser instance.
Step 3: Configure Playwright (Option B - conftest.py):
Alternatively, the browser_type_launch_args
method in conftest.py
can be used, although it may be less reliable.
# conftest.py
import pytest
@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
browser_type_launch_args['args'].append('--disable-features=BlockInsecurePrivateNetworkRequests')
return browser_type_launch_args
Key Takeaways
- Directly configuring Chrome flags might not always persist for Playwright.
- Using
launchOptions
in Playwright's configuration is the most reliable approach. - Verify the setting after applying any changes to ensure it's correctly disabled.
By following these steps, you can effectively disable the "Block insecure private network requests" feature and streamline your Playwright Codegen testing process. If issues persist, double-check your configuration files and Chrome settings for any conflicting rules.