[Question] Is it possible to define host resolution rules per browser instance?
See original GitHub issueIn my daily work, I often have to tweak the /etc/hosts file for routing production site URLs to the development sites for testing.
Is it possible to launch a browser instance with a set of customized host resolution rules? For example,
const browser = await chromium.launch( {
hosts: {
'example.com': '127.0.0.1', // all the request to example.com will then be routed to my local machine.
}
} );
I believe it’s possible by dockerizing my playwright testing program, but would like to see if there is a lightweight solution for this.
Thanks 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Browser with its own hosts file? - Super User
Any solution which simply rewrites the host file doesn't work because of the requirement to run multiple browser windows at the same time...
Read more >DNS attributes for your VPC - Amazon Virtual Private Cloud
You can resolve the Private IP DNS name (IPv4 only) hostnames of other instances in other VPCs as long as the instances are...
Read more >Understanding and Using The Hosts File-Beginners Guide
The hosts file performs a name to IP address mapping and was used on early computer networks for name resolution before DNS was...
Read more >What is DNS? How Domain Name System works - TechTarget
For example, if someone types "example.com" into a web browser, a server behind the ... provide the information necessary to connect users to...
Read more >Altering hostname-IP mapping within a browser - Server Fault
In Chromium, you can use the --host-resolver-rules option to specify a list of mappings. For example:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think the code doesn’t work due to additional quote inside of the rule.
This argument should looks as follows in playwright:
Worked for me to direct all domains to be resolved by my local machine.
For example this loaded the content from my local running webserver: