SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.73k stars 8.02k forks source link

[🐛 Bug]: How to connect runnning firefox to debug #14147

Closed softputer closed 1 week ago

softputer commented 1 week ago

What happened?

i have run firefox in debug mode, command as below: /usr/bin/firefox --no-default-browser-check --no-first-run --no-sandbox --start-maximized --disable-gpu --remote-debugging-port 9222

Then how Can I use selenium to debug it, each time i run selenium script, a new firefox instance will be started

the script is as below:

import os
import time
import json

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException

options = Options()
driver = webdriver.Firefox(options=options)
url = "ddd"
file_path = "/tmp/result.json"

def save_result(result):
    with open(file_path, "w") as file:
        json.dump(result, file)

def main():
    driver.set_page_load_timeout(10)
    try:
        driver.get(url)
    except Exception as e:
        message = f"Failed to load page: {type(e).__name__} - {str(e)}"
        result = {
            "status": "failure",
            "message": message
        }
        save_result(result)

How can we reproduce the issue?

1、start firefox in debug mode, in macos or ubuntu
2、use try to use selenium to connect it 

according to the output, it will always start a new firefox instance

Relevant log output

1718691979212   geckodriver INFO    Listening on 127.0.0.1:52973
1718691979217   webdriver::server   DEBUG   -> POST /session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, ... y": "normal", "browserVersion": null, "moz:firefoxOptions": {"binary": "/usr/bin/firefox", "args": ["--context-existing"]}}}}
1718691979217   geckodriver::capabilities   DEBUG   Trying to read firefox version from ini files
1718691979219   geckodriver::capabilities   DEBUG   Found version 126.0.1
1718691979221   mozrunner::runner   INFO    Running command: MOZ_CRASHREPORTER="1" MOZ_CRASHREPORTER_NO_REPORT="1" MOZ_CRASHREPORTER_SHUTDOWN="1" MOZ_NO_REMOTE="1" "/usr ... ng" "--remote-debugging-port" "38763" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "/tmp/rust_mozprofile62uaao"
1718691979222   geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1
Error: no DISPLAY environment variable specified
1718691979325   geckodriver::browser    DEBUG   Browser process stopped: exit status: 1
1718691979325   webdriver::server   DEBUG   <- 500 Internal Server Error {"value":{"error":"unknown error","message":"Process unexpectedly closed with status 1","stacktrace":""}}

Operating System

ubuntu or macos

Selenium version

4.21.0

What are the browser(s) and version(s) where you see this issue?

firefox 126.0.1

What are the browser driver(s) and version(s) where you see this issue?

0.34

Are you using Selenium Grid?

no

github-actions[bot] commented 1 week ago

@softputer, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] commented 1 week ago

💬 Please ask questions at: