- Notifications
You must be signed in to change notification settings - Fork1
oxylabs/playwright-proxy-integration-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
npm install playwright
Open the following URL in the browser and enter your credentials. You will see a list of proxies in plain text:
https://proxy.oxylabs.io/allIf you wish to select any of the provided proxies, you need to save the proxy IP, along with the port, in a variable.
To use all these proxies, first, save these proxies as an array in your code:
letproxies=['127.0.0.1:60000','127.0.0.2:60000','127.0.0.3:60000','127.0.0.4:60000']
To select one of the proxies randomly, use the following line of code:
varproxy=proxies[Math.floor(Math.random()*proxies.length)];
Create a variable calledlaunchOptions and assign the proxy information to it.
Don't forget to replaceUSERNAME andPASSWORD with your proxy user credentials.
constlaunchOptions={proxy:{server:proxy,username:'USERNAME',password:'PASSWORD'}};
After creating thelaunchOptions variable, create aplaywright instance and launch the browser.
constbrowser=awaitchromium.launch(launchOptions);
For the complete code sample, seethis file.
Proxy information can be supplied as a parameter to thelaunch method ofplaywright instance.
Alternatively, create a variable calledlaunchOptions and assign the proxy information to it.
Don't forget to replaceUSERNAME andPASSWORD with your proxy user credentials.
constlaunchOptions={proxy:{server:'pr.oxylabs.io:7777',username:'USERNAME',password:'PASSWORD'},headless:false};
The additional benefit of using lauchOptions variable is that other information such asheadless can be supplied to thelaunch method.:
After creating thelaunchOptions variable, create aplaywright instance and launch the browser.
constbrowser=awaitchromium.launch(launchOptions);
For the complete code sample, seethis file.
If you wish to use country-specific proxies, all you need to do is change the proxy server.
For example, if you wish to use the proxy for the United States, you can use the following code:
constlaunchOptions={proxy:{server:'us-pr.oxylabs.io:10001',username:'USERNAME',password:'PASSWORD'},headless:false};
In this example, us-pr.oxylabs.io:10000 is the country specific entry point for the United States.
Another example isgb-pr.oxylabs.io:20000, which is the country specific entry point for United Kingdom.
For a complete list of all entry points, seeCountry Specific Entry Nodes.
About
A tutorial for implementing Oxylabs` Residential and Datacenter proxies with Playwright using JavaScript
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
