Skip to content

Commit 03627df

Browse files
committed
logging changes har launch.py
1 parent 491cd3d commit 03627df

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/environments/launch.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def guess_start_url(self) -> Optional[str]:
8888
return resource.get("url")
8989
return None
9090

91-
def _setup_network_logging(self, context: BrowserContext) -> None:
91+
def _setup_har_logging(self, context: BrowserContext) -> None:
9292
"""Set up network event listeners to log requests not found in HAR."""
9393

9494
async def log_request_failed(request):
@@ -216,18 +216,15 @@ async def build_context(
216216
context_config["storage_state"] = "{}"
217217

218218
context = await browser.new_context(**context_config)
219+
self._setup_har_logging(context)
219220

220-
# Set up network logging to track HAR replay issues
221-
self._setup_network_logging(context)
222-
223-
# Use HAR replay first
224221
har_path = self.bundle_path / "recording.har"
225222
if not har_path.exists():
226223
raise FileNotFoundError(
227224
f"HAR file not found at {har_path}. Cannot replay without HAR file."
228225
)
229226

230-
logger.info("Using HAR replay from %s", har_path)
227+
logger.info("[HAR REPLAY] Using HAR replay from %s", har_path)
231228
await context.route_from_har(
232229
str(har_path),
233230
not_found="fallback" if allow_network_fallback else "abort",
@@ -246,6 +243,8 @@ async def handle_routes_manually(self, route, request):
246243
# TODO: what if the request is sent twice, we'll be selecting the first one all the time.
247244

248245
# TODO: this requires LM postprocessing selection of URL's to match or some dumb way for all POST? or smth
246+
# TODO: why when collecting, increasing/decreasing cart stuff fails
247+
# TODO: some assets in GET are also dynamic?, bunch of js/stylesheets are not found in HAR
249248
urls_to_ignore_post_data = {
250249
"https://www.amazon.com/ax/claim",
251250
"https://www.amazon.com/aaut/verify/ap",
@@ -277,7 +276,7 @@ async def handle_routes_manually(self, route, request):
277276
None,
278277
)
279278
if not entry:
280-
continue
279+
break
281280

282281
logger.info(
283282
"✅ Found matching HAR entry for %s",
@@ -292,8 +291,10 @@ async def handle_routes_manually(self, route, request):
292291
await route.fulfill(status=status, headers=headers, body=body)
293292
return
294293

295-
# If not found in HAR, abort it
296-
logger.warning("⚠️ No matching HAR entry found for %s, aborting", request.url)
294+
logger.warning(
295+
"⚠️ No matching HAR entry found for %s, aborting",
296+
request.url[:100] + "..." if len(request.url) > 100 else request.url,
297+
)
297298
await route.abort()
298299

299300
def _storage_state_path(self) -> Optional[Path]:

0 commit comments

Comments
 (0)