Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Take non-default browser target location into account when opening re… #3756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion telemetry/telemetry/internal/app/android_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def _UpdateDevToolsClient(self):
if devtools_client_backend.IsDevToolsAgentAvailable(
self._local_port, self._app_backend):
self._devtools_client = devtools_client_backend.DevToolsClientBackend(
self._local_port, self._remote_devtools_port, self._app_backend)
self._local_port, '/devtools/browser', self._remote_devtools_port,
self._app_backend)

def GetWebViews(self):
webviews = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, platform_backend, supports_tab_control,
browser_options=browser_options,
tab_list_backend=tab_list_backend.TabListBackend)
self._port = None
self._browser_target = None

self._supports_tab_control = supports_tab_control
self._devtools_client = None
Expand Down Expand Up @@ -134,7 +135,8 @@ def GetReplayBrowserStartupArgs(self):

def HasBrowserFinishedLaunching(self):
assert self._port, 'No DevTools port info available.'
return devtools_client_backend.IsDevToolsAgentAvailable(self._port, self)
return devtools_client_backend.IsDevToolsAgentAvailable(self._port,
self._browser_target, self)

def _InitDevtoolsClientBackend(self, remote_devtools_port=None):
""" Initiate the devtool client backend which allow browser connection
Expand All @@ -147,7 +149,8 @@ def _InitDevtoolsClientBackend(self, remote_devtools_port=None):
assert not self._devtools_client, (
'Devtool client backend cannot be init twice')
self._devtools_client = devtools_client_backend.DevToolsClientBackend(
self._port, remote_devtools_port or self._port, self)
self._port, self._browser_target,
remote_devtools_port or self._port, self)

def _WaitForBrowserToComeUp(self):
""" Wait for browser to come up. """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def __init__(self, desktop_platform_backend, browser_options, executable,

self._browser_directory = browser_directory
self._port = None
self._browser_target = None
self._tmp_minidump_dir = tempfile.mkdtemp()
if self.is_logging_enabled:
self._log_file_path = os.path.join(tempfile.mkdtemp(), 'chrome.log')
Expand Down Expand Up @@ -234,9 +235,14 @@ def HasBrowserFinishedLaunching(self):
try:
if os.stat(port_file).st_size > 0:
with open(port_file) as f:
port_string = f.read()
self._port = int(port_string)
port_target = f.read().split('\n')
self._port = int(port_target[0])
if len(port_target) > 1:
self._browser_target = port_target[1]
else:
self._browser_target = '/devtools/browser'
logging.info('Discovered ephemeral port %s', self._port)
logging.info('Browser target: %s', self._browser_target)
got_port = True
except Exception:
# Both stat and open can throw exceptions.
Expand Down Expand Up @@ -301,6 +307,7 @@ def Start(self):
'Chrome log file will be saved in %s\n' % self.log_file_path)
env['CHROME_LOG_FILE'] = self.log_file_path
logging.info('Starting Chrome %s', args)

if not self.browser_options.show_stdout:
self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0)
self._proc = subprocess.Popen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
from tracing.trace_data import trace_data as trace_data_module


BROWSER_INSPECTOR_WEBSOCKET_URL = 'ws://127.0.0.1:%i/devtools/browser'
BROWSER_INSPECTOR_WEBSOCKET_URL = 'ws://127.0.0.1:%i%s'


class TabNotFoundError(exceptions.Error):
pass


def IsDevToolsAgentAvailable(port, app_backend):
def IsDevToolsAgentAvailable(port, browser_target, app_backend):
"""Returns True if a DevTools agent is available on the given port."""
if (isinstance(app_backend, browser_backend.BrowserBackend) and
app_backend.supports_tracing):
inspector_websocket_instance = inspector_websocket.InspectorWebsocket()
try:
if not _IsInspectorWebsocketAvailable(inspector_websocket_instance, port):
if not _IsInspectorWebsocketAvailable(inspector_websocket_instance, port,
browser_target):
return False
finally:
inspector_websocket_instance.Disconnect()
Expand All @@ -48,10 +49,11 @@ def IsDevToolsAgentAvailable(port, app_backend):
devtools_http_instance.Disconnect()


def _IsInspectorWebsocketAvailable(inspector_websocket_instance, port):
def _IsInspectorWebsocketAvailable(inspector_websocket_instance, port,
browser_target):
try:
inspector_websocket_instance.Connect(
BROWSER_INSPECTOR_WEBSOCKET_URL % port, timeout=10)
BROWSER_INSPECTOR_WEBSOCKET_URL % (port, browser_target), timeout=10)
except (websocket.WebSocketException, socket.error) as exc:
logging.info(
'Websocket at port %i not yet available: %s', port, exc)
Expand Down Expand Up @@ -83,7 +85,8 @@ class DevToolsClientBackend(object):
This class owns a map of InspectorBackends. It is responsible for creating
them and destroying them.
"""
def __init__(self, devtools_port, remote_devtools_port, app_backend):
def __init__(self, devtools_port, browser_target, remote_devtools_port,
app_backend):
"""Creates a new DevToolsClientBackend.

A DevTools agent must exist on the given devtools_port.
Expand All @@ -97,6 +100,7 @@ def __init__(self, devtools_port, remote_devtools_port, app_backend):
app_backend: For the app that contains the DevTools agent.
"""
self._devtools_port = devtools_port
self._browser_target = browser_target
self._remote_devtools_port = remote_devtools_port
self._devtools_http = devtools_http.DevToolsHttp(devtools_port)
self._browser_inspector_websocket = None
Expand Down Expand Up @@ -324,14 +328,18 @@ def _CreateSystemInfoBackendIfNeeded(self):
if not self._system_info_backend:
self._CreateAndConnectBrowserInspectorWebsocketIfNeeded()
self._system_info_backend = system_info_backend.SystemInfoBackend(
self._devtools_port)
self._BrowserTargetWebSocket())

def _CreateAndConnectBrowserInspectorWebsocketIfNeeded(self):
if not self._browser_inspector_websocket:
self._browser_inspector_websocket = (
inspector_websocket.InspectorWebsocket())
self._browser_inspector_websocket.Connect(
BROWSER_INSPECTOR_WEBSOCKET_URL % self._devtools_port, timeout=10)
self._BrowserTargetWebSocket(), timeout=10)

def _BrowserTargetWebSocket(self):
return (BROWSER_INSPECTOR_WEBSOCKET_URL %
(self._devtools_port, self._browser_target))

def IsChromeTracingSupported(self):
if not self.supports_tracing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@


class SystemInfoBackend(object):
def __init__(self, devtools_port):
self._port = devtools_port
def __init__(self, browser_target_ws):
self._browser_target_ws = browser_target_ws

def GetSystemInfo(self, timeout=10):
req = {'method': 'SystemInfo.getInfo'}
websocket = inspector_websocket.InspectorWebsocket()
try:
websocket.Connect('ws://127.0.0.1:%i/devtools/browser' % self._port,
timeout)
websocket.Connect(self._browser_target_ws, timeout)
res = websocket.SyncRequest(req, timeout)
finally:
websocket.Disconnect()
Expand Down