Tor in Headless mode

Using selenium and Brave together, the code works fine without headless. But adding the headless argument makes brave work without Tor
Using the code bellow is possible to see the problem in action

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
import sys
from time import sleep
from webdriver_manager.chrome import ChromeDriverManager


ip_element = 'font[color="#FF0000"]'


options = Options()
options.binary_location = r'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'
driver_path = ChromeDriverManager().install()
options.add_argument('--tor')
options.add_argument('--headless')
while True:
    drvr = webdriver.Chrome(options=options, executable_path=driver_path)
    drvr.get('http://meuip.com/')
    sleep(.2)
    ip = drvr.find_element_by_css_selector(ip_element)
    print(ip.text)
    drvr.quit()
breakpoint()

Adding a comment in the line --headless you can see the IP address changing and tor working. With the headless line the connection goes without TOR

Version 1.39.111 Chromium: 102.0.5005.61 (Official Build) (64-bit)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.