ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.99k stars 1.16k forks source link

[nodriver] how can i use a socks5 proxy with authentication? #1903

Open rex1de opened 5 months ago

rex1de commented 5 months ago

i have tried this h

        manifest_json = """
        {
           "version": "1.0.0",
           "manifest_version": 3,
           "name": "Chrome Proxy",
           "permissions": [
             "proxy",
             "tabs",
             "storage",
             "webRequest",
             "webRequestAuthProvider"
           ],
           "host_permissions": [
             "<all_urls>"
           ],
           "background": {
             "service_worker": "background.js"
           },
           "minimum_chrome_version": "22.0.0"
         }
         """

        background_js = """
         var config = {
                 mode: "fixed_servers",
                 rules: {
                 singleProxy: {
                     scheme: "http",
                     host: "%s",
                     port: parseInt(%s)
                 },
                bypassList: ["localhost"]
                 }
             };

         chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

         function callbackFn(details) {
             return {
                 authCredentials: {
                     username: "%s",
                     password: "%s"
                 }
             };
         }

         chrome.webRequest.onAuthRequired.addListener(
                     callbackFn,
                     {urls: ["<all_urls>"]},
                     ['blocking']
         );
         """ % (proxy_host, proxy_port, proxy_login, proxy_pass)

        print(proxy_host, proxy_port, proxy_login, proxy_pass)

        with open(os.path.join(extension_dir, 'manifest.json'), 'w') as f:
             f.write(manifest_json)

        with open(os.path.join(extension_dir, 'background.js'), 'w') as f:
             f.write(background_js)

        driver = await uc.start(browser_args=[f'--load-extension={extension_dir}'])

also tried every scheme, http(s), socks4, socks5 extension loads in, but i cant get to any website proxy is working for sure

rex1de commented 5 months ago

also tried this https://github.com/ultrafunkamsterdam/undetected-chromedriver/discussions/1798, not working too

GooseBumpsOS commented 5 months ago

So, my solutuion:

create dir with proxy exstention

image

Then you do your stuff and before running you must add line

chrome_options.add_argument('--load-extension=./proxies_extension')

For more info you can check this repo, but i modified it before execution https://github.com/Smartproxy/Selenium-proxy-authentication

Zip extension didn't work for me

gun-hash commented 5 months ago

I am trying out using pproxy as a proxy redirectory. so you connect with a http no auth proxy on your local host which communicates with the socks5 proxy with auth.

Its mentioned here - https://stackoverflow.com/questions/43312573/how-to-set-socks5-proxy-with-auth-for-chrome-in-selenium-python

neestzjov commented 2 months ago

So, my solutuion:

create dir with proxy exstention

image

Then you do your stuff and before running you must add line

chrome_options.add_argument('--load-extension=./proxies_extension')

For more info you can check this repo, but i modified it before execution https://github.com/Smartproxy/Selenium-proxy-authentication

Zip extension didn't work for me

Did this work with nodriver?

GooseBumpsOS commented 2 months ago

So, my solutuion: create dir with proxy exstention image Then you do your stuff and before running you must add line

chrome_options.add_argument('--load-extension=./proxies_extension')

For more info you can check this repo, but i modified it before execution https://github.com/Smartproxy/Selenium-proxy-authentication Zip extension didn't work for me

Did this work with nodriver?

totally

ImNotOssy commented 1 month ago

So, my solutuion: create dir with proxy exstention image Then you do your stuff and before running you must add line

chrome_options.add_argument('--load-extension=./proxies_extension')

For more info you can check this repo, but i modified it before execution https://github.com/Smartproxy/Selenium-proxy-authentication Zip extension didn't work for me

Did this work with nodriver?

totally

YO, ive been at this for the past week now and i always get the Manifest file is missing or unreadable. yet i clearly see it on the zip file. it gives me the path of the zip its looking for and i can confirm everything is present yet im getting this silly error.

EDIT: NVM i just fixed it by removing the zip file creation and just making it a plain folder. thank you

jyounus commented 1 month ago

@ImNotOssy Could you please help me get this working with nodriver? What do I need to do with the files in the https://github.com/Smartproxy/Selenium-proxy-authentication repo? They are different compared to the screenshot @GooseBumpsOS posted.

And then how do I modify the start function to make this work?

self.browser = await uc.start(
    headless=False
)
egalimberti commented 1 month ago

i have tried this h

        manifest_json = """
        {
           "version": "1.0.0",
           "manifest_version": 3,
           "name": "Chrome Proxy",
           "permissions": [
             "proxy",
             "tabs",
             "storage",
             "webRequest",
             "webRequestAuthProvider"
           ],
           "host_permissions": [
             "<all_urls>"
           ],
           "background": {
             "service_worker": "background.js"
           },
           "minimum_chrome_version": "22.0.0"
         }
         """

        background_js = """
         var config = {
                 mode: "fixed_servers",
                 rules: {
                 singleProxy: {
                     scheme: "http",
                     host: "%s",
                     port: parseInt(%s)
                 },
                bypassList: ["localhost"]
                 }
             };

         chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

         function callbackFn(details) {
             return {
                 authCredentials: {
                     username: "%s",
                     password: "%s"
                 }
             };
         }

         chrome.webRequest.onAuthRequired.addListener(
                     callbackFn,
                     {urls: ["<all_urls>"]},
                     ['blocking']
         );
         """ % (proxy_host, proxy_port, proxy_login, proxy_pass)

        print(proxy_host, proxy_port, proxy_login, proxy_pass)

        with open(os.path.join(extension_dir, 'manifest.json'), 'w') as f:
             f.write(manifest_json)

        with open(os.path.join(extension_dir, 'background.js'), 'w') as f:
             f.write(background_js)

        driver = await uc.start(browser_args=[f'--load-extension={extension_dir}'])

also tried every scheme, http(s), socks4, socks5 extension loads in, but i cant get to any website proxy is working for sure

I have used these manifest and backgorund_js and finally manged to connect to the proxy with nodriver...thanks!

nonetheless, I have to manually input user and password in the Chrome prompt even if I included them in the js how can I automate this part too? is it working for you?

egalimberti commented 1 month ago

@ImNotOssy Could you please help me get this working with nodriver? What do I need to do with the files in the https://github.com/Smartproxy/Selenium-proxy-authentication repo? They are different compared to the screenshot @GooseBumpsOS posted.

And then how do I modify the start function to make this work?

self.browser = await uc.start(
    headless=False
)

I used the version of the files shared in first comment and the connection is working (but I have to manually input user and password in the Chrome prompt)

ponideal commented 2 days ago

@ImNotOssy Could you please help me get this working with nodriver? What do I need to do with the files in the https://github.com/Smartproxy/Selenium-proxy-authentication repo? They are different compared to the screenshot @GooseBumpsOS posted. And then how do I modify the start function to make this work?

self.browser = await uc.start(
    headless=False
)

I used the version of the files shared in first comment and the connection is working (but I have to manually input user and password in the Chrome prompt)

Couldn't find a solution? I was already thinking of using proxychains