@@ -7,6 +7,9 @@ import { Snapshot } from './types';
77import * as fs from 'fs' ;
88import * as path from 'path' ;
99
10+ // Maximum payload size for API requests (10MB server limit)
11+ const MAX_PAYLOAD_BYTES = 10 * 1024 * 1024 ;
12+
1013export interface SnapshotOptions {
1114 screenshot ?: boolean | { format : 'png' | 'jpeg' ; quality ?: number } ;
1215 limit ?: number ;
@@ -183,6 +186,18 @@ async function snapshotViaApi(
183186 } ,
184187 } ;
185188
189+ // Check payload size before sending (server has 10MB limit)
190+ const payloadJson = JSON . stringify ( payload ) ;
191+ const payloadSize = new TextEncoder ( ) . encode ( payloadJson ) . length ;
192+ if ( payloadSize > MAX_PAYLOAD_BYTES ) {
193+ const sizeMB = ( payloadSize / 1024 / 1024 ) . toFixed ( 2 ) ;
194+ const limitMB = ( MAX_PAYLOAD_BYTES / 1024 / 1024 ) . toFixed ( 0 ) ;
195+ throw new Error (
196+ `Payload size (${ sizeMB } MB) exceeds server limit (${ limitMB } MB). ` +
197+ `Try reducing the number of elements on the page or filtering elements.`
198+ ) ;
199+ }
200+
186201 const headers : Record < string , string > = {
187202 'Authorization' : `Bearer ${ apiKey } ` ,
188203 'Content-Type' : 'application/json' ,
@@ -192,7 +207,7 @@ async function snapshotViaApi(
192207 const response = await fetch ( `${ apiUrl } /v1/snapshot` , {
193208 method : 'POST' ,
194209 headers,
195- body : JSON . stringify ( payload ) ,
210+ body : payloadJson ,
196211 } ) ;
197212
198213 if ( ! response . ok ) {
0 commit comments