def FindAllAvailableBrowsers(finder_options, device): """Find all running iOS browsers on connected devices.""" if not isinstance(device, ios_device.IOSDevice): return [] if not CanFindAvailableBrowsers(): return [] options = finder_options.browser_options options.browser_type = 'ios-chrome' host = platform.GetHostPlatform() backend = ios_browser_backend.IosBrowserBackend(host, options) # TODO(baxley): Use idevice to wake up device or log debug statement. if not host.IsApplicationRunning(IOS_WEBKIT_DEBUG_PROXY): host.LaunchApplication(IOS_WEBKIT_DEBUG_PROXY) if not host.IsApplicationRunning(IOS_WEBKIT_DEBUG_PROXY): return [] device_urls = backend.GetDeviceUrls() if not device_urls: logging.debug('Could not find any devices over %s.' % IOS_WEBKIT_DEBUG_PROXY) return [] debug_urls = backend.GetWebSocketDebuggerUrls(device_urls) # Get the userAgent for each UIWebView to find the browsers. browser_pattern = (r'\)\s(%s)\/(\d+[\.\d]*)\sMobile' % '|'.join(IOS_BROWSERS.keys())) browser_types = set() for url in debug_urls: context = {'webSocketDebuggerUrl': url, 'id': 1} try: inspector = inspector_backend.InspectorBackend( backend.app, backend.devtools_client, context) res = inspector.EvaluateJavaScript("navigator.userAgent") finally: inspector.Disconnect() match_browsers = re.search(browser_pattern, res) if match_browsers: browser_types.add(match_browsers.group(1)) browsers = [] for browser_type in browser_types: browsers.append(PossibleIOSBrowser(IOS_BROWSERS[browser_type], finder_options)) return list(browsers)
def GetInspectorBackend(self, context_id): """Gets an InspectorBackend instance for the given context_id. This lazily creates InspectorBackend for the context_id if it does not exist yet. Otherwise, it will return the cached instance.""" if context_id in self._inspector_backends_dict: return self._inspector_backends_dict[context_id] for context in self._contexts: if context['id'] == context_id: new_backend = inspector_backend.InspectorBackend( self._devtools_client, context) self._inspector_backends_dict[context_id] = new_backend return new_backend raise KeyError('Cannot find a context with id=%s' % context_id)
device_urls = backend.GetDeviceUrls() if not device_urls: logging.debug('Could not find any devices over %s.' % IOS_WEBKIT_DEBUG_PROXY) return [] debug_urls = backend.GetWebSocketDebuggerUrls(device_urls) # Get the userAgent for each UIWebView to find the browsers. browser_pattern = (r'\)\s(%s)\/(\d+[\.\d]*)\sMobile' % '|'.join(IOS_BROWSERS.keys())) browser_types = set() for url in debug_urls: context = {'webSocketDebuggerUrl': url, 'id': 1} try: inspector = inspector_backend.InspectorBackend( backend.app, backend.devtools_client, context) res = inspector.EvaluateJavaScript("navigator.userAgent") finally: inspector.Disconnect() match_browsers = re.search(browser_pattern, res) if match_browsers: browser_types.add(match_browsers.group(1)) browsers = [] for browser_type in browser_types: browsers.append(PossibleIOSBrowser(IOS_BROWSERS[browser_type], finder_options)) return list(browsers)