fix: handle remote-debugging-port=0 correctly (#17800)

By default the Chromedriver will send remote-debugging-port=0 to let the
browser choose a free port to listen on.  The chosen port is written to
a known file in the user data dir that is passed to the app through the
CLI.

This PR does two things.

1. Correctly passes the USER_DATA_DIR to the remote debugging server so
it knows where to write the file
2. Adds support for --user-data-dir as we did not support that CLI
argument and Chromedriver relies on being able to tell the "browser"
where to write this file.

Fixes #17354
This commit is contained in:
Samuel Attard 2019-04-16 14:22:51 -04:00 committed by GitHub
parent be6fb7cb12
commit b7b9efa875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 9 deletions

View file

@ -8,9 +8,11 @@
#include <utility>
#include <vector>
#include "atom/browser/atom_paths.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@ -67,7 +69,7 @@ std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
int temp_port;
std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) && temp_port > 0 &&
if (base::StringToInt(port_str, &temp_port) && temp_port >= 0 &&
temp_port < 65535) {
port = temp_port;
} else {
@ -84,8 +86,10 @@ std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
// static
void DevToolsManagerDelegate::StartHttpHandler() {
base::FilePath user_dir;
base::PathService::Get(DIR_USER_DATA, &user_dir);
content::DevToolsAgentHost::StartRemoteDebuggingServer(
CreateSocketFactory(), base::FilePath(), base::FilePath());
CreateSocketFactory(), user_dir, base::FilePath());
}
DevToolsManagerDelegate::DevToolsManagerDelegate() {}