@@ -31,8 +31,6 @@ use crate::{
3131
3232use super :: domain:: FileUploadV2 ;
3333
34- static GET_VIEW_PORT_JS_SCRIPT : & str = include_str ! ( "get_viewport.js" ) ;
35-
3634#[ derive( Clone ) ]
3735pub struct FileService {
3836 pub store : StoreRepository < FileUploadV2 > ,
@@ -89,26 +87,32 @@ impl FileService {
8987 let file_url = format ! ( "file://{}" , temp_file_path. display( ) ) ;
9088 tab. navigate_to ( & file_url) . map_err ( ServiceError :: new) ?;
9189 tab. wait_until_navigated ( ) . map_err ( ServiceError :: new) ?;
92- let viewport = tab
93- . evaluate ( GET_VIEW_PORT_JS_SCRIPT , true )
94- . map_err ( ServiceError :: new) ?
95- . value
96- . ok_or_else ( || ServiceError :: new ( "Failed to get viewport dimensions" ) ) ?;
9790
98- // Parse viewport dimensions
99- let clip = serde_json:: from_value :: < Viewport > ( viewport)
100- . map_err ( |e| ServiceError :: new ( format ! ( "Failed to parse viewport: {}" , e) ) ) ?;
91+ let first_page_height: f64 = tab
92+ . evaluate ( "document.querySelector('body').scrollHeight" , false )
93+ . map_err ( |e| ServiceError :: new ( e. to_string ( ) ) ) ?
94+ . value
95+ . ok_or_else ( || ServiceError :: new ( "missing height viewport" ) ) ?
96+ . as_f64 ( )
97+ . ok_or_else ( || ServiceError :: new ( "could not parse height viewport" ) ) ?;
98+ let first_page_width: f64 = tab
99+ . evaluate ( "document.querySelector('body').scrollWidth" , false )
100+ . map_err ( |e| ServiceError :: new ( e. to_string ( ) ) ) ?
101+ . value
102+ . ok_or_else ( || ServiceError :: new ( "missing width viewport" ) ) ?
103+ . as_f64 ( )
104+ . ok_or_else ( || ServiceError :: new ( "could not parse width viewport" ) ) ?;
101105
102106 // Capture screenshot with the specific viewport
103107 let png_data = tab
104108 . capture_screenshot (
105109 Page :: CaptureScreenshotFormatOption :: Png ,
106110 None ,
107111 Some ( Page :: Viewport {
108- x : clip . x ,
109- y : clip . y ,
110- width : clip . width ,
111- height : clip . height ,
112+ x : 0. ,
113+ y : 0. ,
114+ width : first_page_width ,
115+ height : first_page_height ,
112116 scale : 1.0 ,
113117 } ) ,
114118 true ,
0 commit comments