Sessions API fails after a session using devtools

This issue has been tracked since 2022-09-21.

Describe the bug
Having issues with /get-sessions after a session is connected to via devtools using tracking_id. We can still connect and spin up new browser connections, but are unable to retrieve the active sessions list and thus cannot connect to devtools for that session. This process all seemed to work fine before we were trying to connect to devtools during sessions.

To Reproduce

  1. To clear state, I relaunched the worker.
  2. I spin up a session using python, and a unique tracking ID
self.driver = webdriver.Remote(
            command_executor=settings.BROWSERLESS_URL,
            desired_capabilities=self.chrome_options.to_capabilities(),
            options=self.options
        )
  1. We call /sessions and find the URL for devtools for this session
  2. We wait for the session to complete and be shut down via python driver.quit()
  3. Devtools window shows the message "browser shutdown"
  4. After this, any call to /sessions returns the following error message:

request to http://127.0.0.1:36405/json/list failed, reason: connect ECONNREFUSED 127.0.0.1:36405

Expected behavior
/sessions should go back to returning an empty list.

qosha1 wrote this answer on 2022-10-02

update:

  • Tried with python selenium v3 & v4. The examples provided in the docs here - python - seem to cause the same issue even without connecting to the devtools url so I guess it's not related to that.
  • Appears to be some sort of error with shutdown of the session after running driver.quit() while using python selenium drivers.

I was able to clear whatever issue this is by calling /kill/all. Not exactly ideal to do that, but may give some indication of where the issue is occuring.

joelgriffith wrote this answer on 2022-10-02

This is very interesting -- do you happen to have a bit more code to provide that we can use to reproduce?

qosha1 wrote this answer on 2022-10-02

Sure... our internal setup is a bit more complicated but i was able to replicate the issue through a terminal using only the code provided in the examples.

I was able to get it with the below sequence. Of course with my api token replaced. If there's other info you want lmk!

# Selenium 4
from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability('browserless:token', 'YOUR-API-TOKEN')
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")

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

driver.get("https://www.example.com")
print(driver.title)
driver.quit()

Then call the
/sessions

api and it returns the error. I am using the dedicated hosted browserless with 1 medium instance.

joelgriffith wrote this answer on 2022-10-02

This should be fixed now in #2718, going to close this out. We'll have production tags for the hosted service ready by mid-week next week!

qosha1 wrote this answer on 2022-10-02

Great to hear! Thanks @joelgriffith for the quick fix - this will make things much smoother for us.

More Details About Repo
Owner Name browserless
Repo Name chrome
Full Name browserless/chrome
Language TypeScript
Created Date 2017-11-17
Updated Date 2023-03-22
Star Count 5309
Watcher Count 47
Fork Count 516
Issue Count 29

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date