def MonitorUrl(connection, url, clear_cache=False, categories=tracing.DEFAULT_CATEGORIES, timeout=devtools_monitor.DEFAULT_TIMEOUT): """Monitor a URL via a trace recorder. Args: connection: A devtools_monitor.DevToolsConnection instance. url: url to navigate to as string. clear_cache: boolean indicating if cache should be cleared before loading. categories: List of tracing event categories to record. timeout: Websocket timeout. Returns: loading_trace.LoadingTrace. """ page = page_track.PageTrack(connection) request = request_track.RequestTrack(connection) trace = tracing.TracingTrack(connection, categories=categories) connection.SetUpMonitoring() if clear_cache: connection.ClearCache() connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) connection.StartMonitoring(timeout=timeout) metadata = { 'date': datetime.datetime.utcnow().isoformat(), 'seconds_since_epoch': time.time() } return loading_trace.LoadingTrace(url, metadata, page, request, trace)
def LoadingTraceFromEvents(requests, page_events=None, trace_events=None): """Returns a LoadingTrace instance from a list of requests and page events.""" request = FakeRequestTrack(requests) page_event_track = FakePageTrack(page_events if page_events else []) if trace_events: tracing_track = tracing.TracingTrack(None) tracing_track.Handle('Tracing.dataCollected', {'params': {'value': [e for e in trace_events]}}) else: tracing_track = None return loading_trace.LoadingTrace( None, None, page_event_track, request, tracing_track)
def LoadingTraceFromEvents(requests, page_events=None, trace_events=None): """Returns a LoadingTrace instance from various events.""" request = FakeRequestTrack(requests) page_event_track = FakePageTrack(page_events if page_events else []) if trace_events is not None: track = tracing_track.TracingTrack(None, clovis_constants.DEFAULT_CATEGORIES) track.Handle('Tracing.dataCollected', {'params': { 'value': [e for e in trace_events] }}) else: track = None return loading_trace.LoadingTrace(None, None, page_event_track, request, track)
def LoadingTrace(events): return loading_trace.LoadingTrace('http://a.com/', {}, page_track.PageTrack(None), request_track.RequestTrack(None), TracingTrack(events))