-1

i'm trying to use Guest Profile for loading Chrome via selenium & python, everything works perfect if i run the python file from terminal, but if i run it by calling it from php it throws an error. (I'm using Xampp as apache server on Macos.) That folder is not in use, also there is no Chrome instance using that profile.

Setting the profile: chrome_options.add_argument("--user-data-dir=/Users/chris/Library/Application Support/Google/Chrome/Guest Profile")

Error: selenium.common.exceptions.WebDriverException: Message: unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at /Users/chris/Library/Application Support/Google/Chrome/Guest Profile is still attached to a running Chrome or Chromium process

I changed permissions to 755 to "Guest Profile" folder, but nothing changes.

Removing chrome option "--user-data-dir...." python scripts works perfect calling it from php Example: http://localhost/test.php?imei=xxxxxxxxxx

$imei = $_GET['imei'];
$command = escapeshellcmd('/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 /Applications/XAMPP/xamppfiles/htdocs/test.py '.$imei);
echo $output = shell_exec($command);
CrY
  • 1
  • 1
  • 4

1 Answers1

0

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at /Users/chris/Library/Application Support/Google/Chrome/Guest Profile is still attached to a running Chrome or Chromium process

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. session for either of the following reasons:

  • There are dangling instance(s) of ChromeDriver process which are still attached to the system memory.
  • You have a manually opened session already running which uses the same Guest Profile.

As per RemoveOldDevToolsActivePortFile():

Status RemoveOldDevToolsActivePortFile(const base::FilePath& user_data_dir) {
  base::FilePath port_filepath = user_data_dir.Append(kDevToolsActivePort);
  // Note that calling DeleteFile on a path that doesn't exist returns True.
  if (base::DeleteFile(port_filepath)) {
    return Status(kOk);
  }
  return Status(
      kUnknownError,
      base::StringPrintf(
          "Could not remove old devtools port file. Perhaps the given "
          "user-data-dir at %s is still attached to a running %s or "
          "Chromium process",
          user_data_dir.AsUTF8Unsafe().c_str(), kBrowserShortName));
}

Solution

You need follow a few rules/steps:

  • Do not manually use/access the designated test profile i.e. Guest Profile.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your reply but the folder is not in use, and it works if i run the .py script in terminal, but gives that error if i start it using php. – CrY Aug 14 '22 at 07:02