@@ -159,11 +159,12 @@ def __init__(self, harfile: Path, capture_uuid: str):
159
159
# Used to find the root entry of a page in the capture
160
160
# NOTE 2020-05-19: Turns out multiple pages can have the exact same timestamp...
161
161
self .pages_start_times : dict [str , list [dict [str , Any ]]] = defaultdict (list )
162
- for page in self .har ['log' ]['pages' ]:
163
- self .pages_start_times [page ['startedDateTime' ]].append (page )
164
- # The first entry has a different start time as the one from the list, add that
165
- if self .entries :
166
- self .pages_start_times [self .initial_start_time ].append (self .har ['log' ]['pages' ][0 ])
162
+ if 'pages' in self .har ['log' ]:
163
+ for page in self .har ['log' ]['pages' ]:
164
+ self .pages_start_times [page ['startedDateTime' ]].append (page )
165
+ # The first entry has a different start time as the one from the list, add that
166
+ if self .entries :
167
+ self .pages_start_times [self .initial_start_time ].append (self .har ['log' ]['pages' ][0 ])
167
168
168
169
# Set to false if initial_redirects fails to find the chain.
169
170
self .need_tree_redirects = False
@@ -200,7 +201,7 @@ def number_entries(self) -> int:
200
201
@property
201
202
def initial_title (self ) -> str :
202
203
"""Title of the first page in the capture"""
203
- if self .har ['log' ]['pages' ][0 ]['title' ]:
204
+ if 'pages' in self . har [ 'log' ] and self .har ['log' ]['pages' ][0 ]['title' ]:
204
205
return self .har ['log' ]['pages' ][0 ]['title' ]
205
206
else :
206
207
return '!! No title found !!'
@@ -670,10 +671,12 @@ def _make_subtree_fallback(self, node: URLNode, dev_debug: bool=False) -> None:
670
671
671
672
# Sometimes, the har has a list of pages, generally when we have HTTP redirects.
672
673
# IF we have more than one page in the list
673
- # AND the orphan node's pageref points to an other page than the first one <= FIXME not enabled yet
674
+ # AND the orphan node's pageref points to an other page than the first one
674
675
# AND we already have a node in the tree with this pageref
675
676
# => attach to that node.
676
- if len (self .har .har ['log' ]['pages' ]) > 1 and node .pageref != self .har .har ['log' ]['pages' ][0 ] and self .pages_root [node .pageref ] != node .uuid :
677
+ if ('pages' in self .har .har ['log' ] and len (self .har .har ['log' ]['pages' ]) > 1
678
+ and node .pageref != self .har .har ['log' ]['pages' ][0 ]
679
+ and self .pages_root [node .pageref ] != node .uuid ):
677
680
# In that case, we check if there is already a page with the pageref of the orphan node,
678
681
# and attach the node to that. NOTE: we can only do that if there is already a node with this pageref in the tree.
679
682
# This node is not a page root, we can attach it \o/
@@ -689,7 +692,7 @@ def _make_subtree_fallback(self, node: URLNode, dev_debug: bool=False) -> None:
689
692
if dev_debug :
690
693
self .logger .warning (f'Failed to attach URLNode in the normal process, attaching node to final redirect: { self .har .final_redirect } .' )
691
694
self ._make_subtree (self .url_tree .search_nodes (name = self .har .final_redirect )[0 ], [node ])
692
- else :
695
+ elif 'pages' in self . har . har [ 'log' ] :
693
696
# No luck, the node is root for this pageref, let's attach it to the prior page in the list, or the very first node (tree root)
694
697
page_before = self .har .har ['log' ]['pages' ][0 ]
695
698
for page in self .har .har ['log' ]['pages' ][1 :]:
@@ -711,6 +714,9 @@ def _make_subtree_fallback(self, node: URLNode, dev_debug: bool=False) -> None:
711
714
page_root_node = self .url_tree
712
715
self .logger .warning ('The pages in the HAR are in in the wrong order, this should not happen but here we are' )
713
716
self ._make_subtree (page_root_node , [node ])
717
+ else :
718
+ # no way to attach it to anything else, attach to the root node
719
+ self ._make_subtree (self .url_tree , [node ])
714
720
715
721
@trace_make_subtree
716
722
def _make_subtree (self , root : URLNode , nodes_to_attach : list [URLNode ] | None = None , dev_debug : bool = False ) -> None :
0 commit comments