File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212from .browser import SentienceBrowser
1313from .models import Snapshot , SnapshotOptions
1414
15+ # Maximum payload size for API requests (10MB server limit)
16+ MAX_PAYLOAD_BYTES = 10 * 1024 * 1024
17+
1518
1619def _save_trace_to_file (raw_elements : list [dict [str , Any ]], trace_path : str | None = None ) -> None :
1720 """
@@ -221,6 +224,16 @@ def _snapshot_via_api(
221224 },
222225 }
223226
227+ # Check payload size before sending (server has 10MB limit)
228+ payload_json = json .dumps (payload )
229+ payload_size = len (payload_json .encode ("utf-8" ))
230+ if payload_size > MAX_PAYLOAD_BYTES :
231+ raise ValueError (
232+ f"Payload size ({ payload_size / 1024 / 1024 :.2f} MB) exceeds server limit "
233+ f"({ MAX_PAYLOAD_BYTES / 1024 / 1024 :.0f} MB). "
234+ f"Try reducing the number of elements on the page or filtering elements."
235+ )
236+
224237 headers = {
225238 "Authorization" : f"Bearer { browser .api_key } " ,
226239 "Content-Type" : "application/json" ,
@@ -229,7 +242,7 @@ def _snapshot_via_api(
229242 try :
230243 response = requests .post (
231244 f"{ browser .api_url } /v1/snapshot" ,
232- json = payload ,
245+ data = payload_json , # Reuse already-serialized JSON
233246 headers = headers ,
234247 timeout = 30 ,
235248 )
You can’t perform that action at this time.
0 commit comments