Exemplo n.º 1
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "chrome");

            // Create a new profile with recommended settings
            // Choose one of the Chrome BaseProfiles
            // You can setup here all of the profile options like WebGL, password manager and start page
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetWebgl("noise", new WebglSpoofingOptions("Google Inc.", "ANGLE (Intel(R) HD Graphics 630 Direct3D11 vs_5_0 ps_5_0)"))
                                       .SetPasswordManager("enabled")
                                       .SetStartPage("https://kameleo.io")
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 2
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient();

            client.SetRetryPolicy(null);

            // Search Firefox Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync("desktop", null, "firefox", null);

            // Create a new profile with recommended settings
            // Choose one of the Firefox BaseProfiles
            // You can set your proxy up in the setProxy method
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetRecommendedDefaults()
                                       .SetProxy("socks5", new Server("<proxy_host>", 1080, "<username>", "<password>"))
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 3
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient();

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync("desktop", null, "chrome", null);

            // Create a new profile with recommended settings
            // Choose one of the Chrome BaseProfiles
            // You can setup here all of the profile options like Webgl
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetLauncher("external")
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            var port = await client.StartProfileAsync(profile.Id);

            if (port.ExternalSpoofingEnginePort != null)
            {
                await RunPuppeteer(port.ExternalSpoofingEnginePort.Value);
            }

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 4
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Firefox Base Profiles
            var baseProfiles = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "firefox");

            // Create a new profile with recommended settings
            // for browser fingerprint protection
            var requestBody = BuilderForCreateProfile
                              .ForBaseProfile(baseProfiles[0].Id)
                              .SetRecommendedDefaults()
                              .Build();

            var profile = await client.CreateProfileAsync(requestBody);

            // Start the browser
            await client.StartProfileAsync(profile.Id);

            // Connect to the browser with Playwright
            var browserWsEndpoint = $"ws://localhost:{KameleoPort}/playwright/{profile.Id}";
            var playwright        = await Playwright.CreateAsync();

            var browser = await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions
            {
                // The Playwright framework is not designed to connect to already running
                // browsers. To overcome this limitation, a tool bundled with Kameleo, named
                // pw-bridge.exe will bridge the communication gap between the running Firefox
                // instance and this playwright script.
                ExecutablePath = "<PATH_TO_KAMELEO_FOLDER>\\pw-bridge.exe",
                Args           = new List <string> {
                    $"-target {browserWsEndpoint}"
                },
            });

            // Kameleo will open the a new page in the default browser context.
            // NOTE: We DO NOT recommend using multiple browser contexts, as this might interfere
            //       with Kameleo's browser fingerprint modification features.
            var page = await browser.NewPageAsync();

            // Use any Playwright command to drive the browser
            // and enjoy full protection from bot detection products
            await page.GotoAsync("https://google.com");

            await page.ClickAsync("div[aria-modal='true'][tabindex='0'] button + button");

            await page.ClickAsync("[name=q]");

            await page.Keyboard.TypeAsync("Kameleo");

            await page.Keyboard.PressAsync("Enter");

            // Wait for 5 seconds
            await page.WaitForTimeoutAsync(5000);

            // Stop the browser by stopping the Kameleo profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 5
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient();

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync("desktop", null, "chrome", null);

            // Create a new profile with recommended settings
            // Choose one of the Chrome BaseProfiles
            // You can setup here all of the profile options
            // Set the launcher "chromium" for launching chromium
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetLauncher("chromium")
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 6
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfiles = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "chrome");

            // Create a new profile with recommended settings
            // for browser fingerprint protection
            var requestBody = BuilderForCreateProfile
                              .ForBaseProfile(baseProfiles[0].Id)
                              .SetRecommendedDefaults()
                              .Build();

            var profile = await client.CreateProfileAsync(requestBody);

            // Start the browser
            await client.StartProfileAsync(profile.Id);

            // Connect to the browser with Playwright through CDP
            var browserWsEndpoint = $"ws://localhost:{KameleoPort}/playwright/{profile.Id}";
            var playwright        = await Playwright.CreateAsync();

            var browser = await playwright.Chromium.ConnectOverCDPAsync(browserWsEndpoint);

            // It is recommended to work on the default context.
            // NOTE: We DO NOT recommend using multiple browser contexts, as this might interfere
            //       with Kameleo's browser fingerprint modification features.
            var context = browser.Contexts[0];
            var page    = await context.NewPageAsync();

            // Use any Playwright command to drive the browser
            // and enjoy full protection from bot detection products
            await page.GotoAsync("https://google.com");

            await page.ClickAsync("div[aria-modal='true'][tabindex='0'] button + button");

            await page.ClickAsync("[name=q]");

            await page.Keyboard.TypeAsync("Kameleo");

            await page.Keyboard.PressAsync("Enter");

            // Wait for 5 seconds
            await page.WaitForTimeoutAsync(5000);

            // Stop the browser by stopping the Kameleo profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 7
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search a Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync();

            // Choose one of from BaseProfiles
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);

            // save the profile to a given path
            var result = await client.SaveProfileAsync(profile.Id, new SaveProfileRequest(Path.Combine(Environment.CurrentDirectory, "test.kameleo")));

            Console.WriteLine("Profile has been saved to " + result.LastKnownPath);

            // You have to delete this profile if you want to load back
            await client.DeleteProfileAsync(profile.Id);

            // load the profile from the given url
            profile = await client.LoadProfileAsync(new LoadProfileRequest(Path.Combine(Environment.CurrentDirectory, "test.kameleo")));

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 8
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfiles = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "chrome");

            // Create a new profile with recommended settings
            // for browser fingerprint protection
            var requestBody = BuilderForCreateProfile
                              .ForBaseProfile(baseProfiles[0].Id)
                              .SetRecommendedDefaults()
                              .Build();

            var profile = await client.CreateProfileAsync(requestBody);

            // Start the browser
            await client.StartProfileAsync(profile.Id);

            // Connect to the browser through CDP
            var browserWsEndpoint = $"ws://localhost:{KameleoPort}/puppeteer/{profile.Id}";
            var browser           = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browserWsEndpoint, DefaultViewport = null });

            var page = await browser.NewPageAsync();

            // Use any Puppeteer command to drive the browser
            // and enjoy full protection from bot detection products
            await page.GoToAsync("https://google.com");

            await page.ClickAsync("div[aria-modal='true'][tabindex='0'] button + button");

            await page.ClickAsync("[name=q]");

            await page.Keyboard.TypeAsync("Kameleo");

            await page.Keyboard.PressAsync("Enter");

            // Wait for 5 seconds
            await page.WaitForTimeoutAsync(5000);

            // Stop the browser by stopping the Kameleo profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 9
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfiles = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "chrome");

            // Create a new profile with recommended settings
            // for browser fingerprint protection
            var requestBody = BuilderForCreateProfile
                              .ForBaseProfile(baseProfiles[0].Id)
                              .SetRecommendedDefaults()
                              .Build();

            var profile = await client.CreateProfileAsync(requestBody);

            // Start the browser
            await client.StartProfileAsync(profile.Id);

            // Connect to the running browser instance using WebDriver
            var uri  = new Uri($"http://localhost:{KameleoPort}/webdriver");
            var opts = new ChromeOptions();

            opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
            var webdriver = new RemoteWebDriver(uri, opts);


            // Use any WebDriver command to drive the browser
            // and enjoy full protection from bot detection products
            webdriver.Navigate().GoToUrl("https://google.com");
            webdriver.FindElement(By.CssSelector("div[aria-modal=\"true\"][tabindex=\"0\"] button + button")).Click();
            webdriver.FindElement(By.Name("q")).SendKeys("Kameleo");
            webdriver.FindElement(By.Name("q")).SendKeys(Keys.Enter);
            var wait = new WebDriverWait(webdriver, TimeSpan.FromSeconds(10));

            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("result-stats")));
            var title = webdriver.Title;

            Console.WriteLine("The title is " + title);

            // Stop the browser by stopping the Kameleo profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 10
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search Chrome Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "chrome");

            // Create a new profile with recommended settings
            // Choose one of the Chrome BaseProfiles
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Provide additional settings for the webdriver when starting the browser
            await client.StartProfileWithWebDriverSettingsAsync(profile.Id, new WebDriverSettings
            {
                Arguments = new List <string> {
                    "mute-audio"
                },
                Preferences = new List <Preference>
                {
                    new Preference("profile.managed_default_content_settings.images", 2),
                    new Preference("profile.password_manager_enabled.images", 2),
                },
                AdditionalOptions = new List <Preference>
                {
                    new Preference("pageLoadStrategy", "eager"),
                }
            });

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 11
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search a Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync();

            // Create a new profile with recommended settings
            // Choose one of the BaseProfiles
            // You can setup here all of the profile options
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetRecommendedDefaults()
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Change every properties what you want to update
            // Others should be the same
            var updateRequestBody = new UpdateProfileRequest(profile)
            {
                StartPage = "https://www.google.com",
                Canvas    = "noise",
            };

            // Send the update request and the response will be your new profile
            profile = await client.UpdateProfileAsync(profile.Id, updateRequestBody);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Wait for 10 seconds
            await Task.Delay(10000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);
        }
Exemplo n.º 12
0
        static async Task Main()
        {
            var client = new KameleoLocalApiClient(new Uri($"http://localhost:{KameleoPort}"));

            client.SetRetryPolicy(null);

            // Search a Base Profiles
            var baseProfileList = await client.SearchBaseProfilesAsync(deviceType : "desktop", browserProduct : "firefox");

            // Create a new profile with recommended settings
            var createProfileRequest = BuilderForCreateProfile
                                       .ForBaseProfile(baseProfileList[0].Id)
                                       .SetRecommendedDefaults()
                                       .Build();

            var profile = await client.CreateProfileAsync(createProfileRequest);

            // Start the profile
            await client.StartProfileAsync(profile.Id);

            // Connect to the profile using WebDriver protocol
            var uri  = new Uri($"http://localhost:{KameleoPort}/webdriver");
            var opts = new ChromeOptions();

            opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
            var webdriver = new RemoteWebDriver(uri, opts);


            // Navigate to a site which give you cookies
            webdriver.Navigate().GoToUrl("https://google.com");
            await Task.Delay(5000);

            webdriver.Navigate().GoToUrl("https://whoer.net");
            await Task.Delay(5000);

            webdriver.Navigate().GoToUrl("https://www.youtube.com");
            await Task.Delay(5000);

            // Stop the profile
            await client.StopProfileAsync(profile.Id);

            // You can list all of your cookies
            var cookieList = await client.ListCookiesAsync(profile.Id);

            Console.WriteLine("The cookies of the profile: ");
            foreach (var cookie in cookieList)
            {
                Console.WriteLine($"{cookie.Domain}, {cookie.Path}, {cookie.Name}");
            }

            // You can modify cookie or you can add new
            var newCookie = cookieList[0];

            newCookie.Value = "123";
            var cookiesArray = new List <CookieRequest> {
                new CookieRequest(newCookie)
            };
            await client.AddCookiesAsync(profile.Id, cookiesArray);

            // You can delete all cookies of the profile
            await client.DeleteCookiesAsync(profile.Id);
        }