FSystem88 / socks5-for-chrome

This Chrome extension allows you to easily connect and disconnect from a SOCKS5 proxy server hosted on your own server.
https://fsystem88.ru/
0 stars 0 forks source link

How to implement the shortest code to enable the proxy by loading it by default without requiring interface settings? #1

Open edus2024 opened 1 day ago

edus2024 commented 1 day ago

As stated in the title

edus2024 commented 1 day ago

manifest.json

{
            "version": "1.0.0",
            "manifest_version": 3,
            "description": "Configure your browser with socks5 proxy",
            "homepage_url": "http://localhost",
            "name": "Proxy",
            "permissions": [
                "activeTab",
                "tabs",
                "proxy",                
                "webRequest",
                "webRequestAuthProvider",
                "storage",                
                "unlimitedStorage",
                "notifications"
            ],

            "host_permissions": [     
                "http://*/*",
                "https://*/*",
                "<all_urls>"
            ],

            "background": {
                //"scripts": ["background.js"]
                "service_worker": "background.js"
            },
            "minimum_chrome_version":"22.0.0"
        }

backgroud.js

            var config = {
                mode: "fixed_servers",
                rules: {
                    singleProxy: {
                        scheme: "socks5",
                        host: "127.0.0.1",
                        port: parseInt(10808)
                    },
                    bypassList: ["localhost"]
                }
            };

            chrome.proxy.settings.set({value: config,scope: 'regular'}, function() {
                if (chrome.runtime.lastError) {
                    console.log(`Error: ${chrome.runtime.lastError.message}`);
                  } else {
                    console.log('Proxy enabled',"Proxy settings set successfully.");
                  }

            });

            function callbackFn(details) {
                return {
                    authCredentials: {
                        username: "root",
                        password: "12345"
                    }
                };
            }

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

            console.log("Proxy and webRequest listeners configured.");

The browser cannot access the network. Using other proxy tools can indeed access the network.