def _Initialize(self): """Initializes the trace task handler. Can be called multiple times.""" if self._is_initialized: return self._is_initialized = True self._xvfb_process = xvfb_helper.LaunchXvfb() # Recover any existing traces in case the worker died. self._DownloadTraceDatabase() if self._trace_database.ToJsonDict(): # There are already files from a previous run in the directory, likely # because the script is restarting after a crash. self._failure_database.AddFailure(FailureDatabase.DIRTY_STATE_ERROR, 'trace_database')
def _LogRequests(url, clear_cache_override=None): """Logs requests for a web page. Args: url: url to log as string. clear_cache_override: if not None, set clear_cache different from OPTIONS. Returns: JSON dict of logged information (ie, a dict that describes JSON). """ xvfb_process = None if OPTIONS.local: chrome_ctl = controller.LocalChromeController() if OPTIONS.headless: xvfb_process = xvfb_helper.LaunchXvfb() chrome_ctl.SetChromeEnvOverride(xvfb_helper.GetChromeEnvironment()) else: chrome_ctl = controller.RemoteChromeController( device_setup.GetFirstDevice()) clear_cache = (clear_cache_override if clear_cache_override is not None else OPTIONS.clear_cache) if OPTIONS.emulate_device: chrome_ctl.SetDeviceEmulation(OPTIONS.emulate_device) if OPTIONS.emulate_network: chrome_ctl.SetNetworkEmulation(OPTIONS.emulate_network) try: with chrome_ctl.Open() as connection: if clear_cache: connection.ClearCache() trace = loading_trace.LoadingTrace.RecordUrlNavigation( url, connection, chrome_ctl.ChromeMetadata(), categories=clovis_constants.DEFAULT_CATEGORIES) except controller.ChromeControllerError as e: e.Dump(sys.stderr) raise if xvfb_process: xvfb_process.terminate() return trace.ToJsonDict()