wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

Is it possible to use browserless? #225

Closed kshnkvn closed 3 years ago

kshnkvn commented 3 years ago

I use the browserless service to work with selenium and I would like to use selenium-wire, but what should I specify in the settings? Here's how to configure the browserless connections:

chrome_options = webdriver.ChromeOptions()

chrome_options.set_capability('browserless.token', f'{token}')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')

driver = webdriver.Remote(
  command_executor='https://chrome.browserless.io/webdriver',
  desired_capabilities=chrome_options.to_capabilities()
)

I have tried specifying seleniumwire_options={'addr': 'https://chrome.browserless.io/webdriver'} but that just throws an error:

ServerException: Error starting mitmproxy server: gaierror(-2, 'Name or service not known')
wkeeling commented 3 years ago

Is the machine you're running Seleniumwire on public - does it have a public facing IP? Basically in order to capture requests, Selenium Wire will redirect traffic through an internal proxy server it starts in the background. So if the IP of the machine is public it shouldn't be too difficult to set that up.

kshnkvn commented 3 years ago

@wkeeling I will ask the browserless technical support.

kshnkvn commented 3 years ago

@wkeeling I was given a large list of IP addresses, as far as I understand, I can use them all, but when I try to do this:

wire_options = {'addr': '159.89.154.221'}
prefs = {profile.managed_default_content_settings.images': 2}

chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability('browserless.token', token)
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_experimental_option('prefs', prefs)

driver = webdriver.Remote(
  command_executor='https://chrome.browserless.io/webdriver',
  desired_capabilities=chrome_options.to_capabilities(),
  seleniumwire_options=wire_options
)

I still have the same error.

wkeeling commented 3 years ago

OK thanks. So just to clarify, you're running Selenium Wire on the machine with IP 159.89.154.221? It looks as though Selenium Wire tries and fails to bind to that local IP. I guess it's possible that the IP is virtual, i.e. mapped through publicly but not bound to an interface on the machine. That might make this tricky to resolve.

kshnkvn commented 3 years ago

@wkeeling oh sorry, looks like I made a mistake. Do I have to specify the IP of the machine on which I run the selenium-wire script, that is, my computer must have public access?

wkeeling commented 3 years ago

Ah, sorry it probably wasn't clear from my original explanation. Yes you'll need to use the public IP of the machine that's running the Selenium Wire code - so that the browser can send traffic back to Selenium Wire for capture. I suppose that may be tricky if you're using your local computer, unless you're able to route the traffic through to it somehow?

kshnkvn commented 3 years ago

@wkeeling okay, now this is definitely clearly. I think the question can be closed, I will try to open access to the local computer. Thanks for the clarification.