def RecordUrlNavigation(
      cls, url, connection, chrome_metadata, additional_categories=None,
      timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS):
    """Create a loading trace by using controller to fetch url.

    Args:
      url: (str) url to fetch.
      connection: An opened devtools connection.
      chrome_metadata: Dictionary of chrome metadata.
      additional_categories: ([str] or None) TracingTrack additional categories
                             to capture.
      timeout_seconds: monitoring connection timeout in seconds.

    Returns:
      LoadingTrace instance.
    """
    page = page_track.PageTrack(connection)
    request = request_track.RequestTrack(connection)
    trace = tracing.TracingTrack(
        connection,
        additional_categories=additional_categories)
    start_date_str = datetime.datetime.utcnow().isoformat()
    seconds_since_epoch=time.time()
    connection.MonitorUrl(url, timeout_seconds=timeout_seconds)
    trace = cls(url, chrome_metadata, page, request, trace)
    trace.metadata.update(date=start_date_str,
                          seconds_since_epoch=seconds_since_epoch)
    return trace
Beispiel #2
0
    def RecordUrlNavigation(
            cls,
            url,
            connection,
            chrome_metadata,
            categories,
            timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS,
            stop_delay_multiplier=0):
        """Create a loading trace by using controller to fetch url.

    Args:
      url: (str) url to fetch.
      connection: An opened devtools connection.
      chrome_metadata: Dictionary of chrome metadata.
      categories: as in tracing.TracingTrack
      timeout_seconds: monitoring connection timeout in seconds.
      stop_delay_multiplier: How long to wait after page load completed before
        tearing down, relative to the time it took to reach the page load to
        complete.

    Returns:
      LoadingTrace instance.
    """
        page = page_track.PageTrack(connection)
        request = request_track.RequestTrack(connection)
        trace = tracing.TracingTrack(connection, categories)
        start_date_str = datetime.datetime.utcnow().isoformat()
        seconds_since_epoch = time.time()
        connection.MonitorUrl(url,
                              timeout_seconds=timeout_seconds,
                              stop_delay_multiplier=stop_delay_multiplier)
        trace = cls(url, chrome_metadata, page, request, trace)
        trace.metadata.update(date=start_date_str,
                              seconds_since_epoch=seconds_since_epoch)
        return trace
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)
Beispiel #4
0
    def RecordUrlNavigation(
            cls,
            url,
            connection,
            chrome_metadata,
            categories=None,
            timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS):
        """Create a loading trace by using controller to fetch url.

    Args:
      url: (str) url to fetch.
      connection: An opened devtools connection.
      chrome_metadata: Dictionary of chrome metadata.
      categories: TracingTrack categories to capture.
      timeout_seconds: monitoring connection timeout in seconds.

    Returns:
      LoadingTrace instance.
    """
        page = page_track.PageTrack(connection)
        request = request_track.RequestTrack(connection)
        trace = tracing.TracingTrack(
            connection,
            categories=(tracing.DEFAULT_CATEGORIES
                        if categories is None else categories))
        connection.MonitorUrl(url, timeout_seconds=timeout_seconds)
        return cls(url, chrome_metadata, page, request, trace)
Beispiel #5
0
def LoadingTrace(events):
    return loading_trace.LoadingTrace('http://a.com/', {},
                                      page_track.PageTrack(None),
                                      request_track.RequestTrack(None),
                                      TracingTrack(events))