@@ -10,13 +10,15 @@ import {
1010 BROWSER_TAB_REFERENCE_HELP ,
1111 callBrowserRequest ,
1212 parseBrowserNonNegativeIntegerValue ,
13+ parseBrowserPositiveIntegerOption ,
1314 parseBrowserPositiveIntegerValue ,
1415 type BrowserParentOpts ,
1516} from "./browser-cli-shared.js" ;
1617import {
1718 danger ,
1819 defaultRuntime ,
1920 getRuntimeConfig ,
21+ inheritOptionFromParent ,
2022 shortenHomePath ,
2123 type SnapshotResult ,
2224} from "./core-api.js" ;
@@ -54,6 +56,22 @@ function parseBrowserChoiceOption<const T extends string>(
5456 return undefined ;
5557}
5658
59+ function resolveBrowserInspectTimeout (
60+ command : Command ,
61+ parent : BrowserParentOpts ,
62+ value : string | undefined ,
63+ ) : { parent : BrowserParentOpts ; timeoutMs ?: number } {
64+ const timeout =
65+ command . getOptionValueSource ( "timeout" ) === "cli"
66+ ? value
67+ : inheritOptionFromParent < string > ( command , "timeout" , "cli" ) ;
68+ if ( timeout === undefined ) {
69+ return { parent } ;
70+ }
71+ const timeoutMs = parseBrowserPositiveIntegerOption ( timeout , "--timeout" ) ;
72+ return { parent : { ...parent , timeout : String ( timeoutMs ) } , timeoutMs } ;
73+ }
74+
5775/** Registers Browser screenshot and snapshot commands. */
5876export function registerBrowserInspectCommands (
5977 browser : Command ,
@@ -72,6 +90,7 @@ export function registerBrowserInspectCommands(
7290 false ,
7391 )
7492 . option ( "--type <png|jpeg>" , "Output type (default: png)" , "png" )
93+ . option ( "--timeout <ms>" , "Timeout in ms" )
7594 . action ( async ( targetId : string | undefined , opts , cmd ) => {
7695 const parent = parentOpts ( cmd ) ;
7796 const profile = parent ?. browserProfile ;
@@ -80,7 +99,8 @@ export function registerBrowserInspectCommands(
8099 return ;
81100 }
82101 try {
83- const result = await callBrowserRequest < { path : string } > ( parent , {
102+ const request = resolveBrowserInspectTimeout ( cmd , parent , opts . timeout ) ;
103+ const result = await callBrowserRequest < { path : string } > ( request . parent , {
84104 method : "POST" ,
85105 path : "/screenshot" ,
86106 query : profile ? { profile } : undefined ,
@@ -91,6 +111,7 @@ export function registerBrowserInspectCommands(
91111 element : normalizeOptionalString ( opts . element ) ,
92112 labels : Boolean ( opts . labels ) ,
93113 type,
114+ ...( request . timeoutMs === undefined ? { } : { timeoutMs : request . timeoutMs } ) ,
94115 } ,
95116 } ) ;
96117 if ( parent ?. json ) {
@@ -120,6 +141,7 @@ export function registerBrowserInspectCommands(
120141 . option ( "--labels" , "Include label overlay screenshot with annotations" , false )
121142 . option ( "--urls" , "Append discovered link URLs to AI snapshots" , false )
122143 . option ( "--out <path>" , "Write snapshot to a file" )
144+ . option ( "--timeout <ms>" , "Timeout in ms" )
123145 . action ( async ( opts , cmd : Command ) => {
124146 const parent = parentOpts ( cmd ) ;
125147 const profile = parent ?. browserProfile ;
@@ -152,6 +174,7 @@ export function registerBrowserInspectCommands(
152174 return ;
153175 }
154176 try {
177+ const request = resolveBrowserInspectTimeout ( cmd , parent , opts . timeout ) ;
155178 const query : Record < string , string | number | boolean | undefined > = {
156179 format,
157180 targetId : normalizeOptionalString ( opts . targetId ) ,
@@ -165,8 +188,9 @@ export function registerBrowserInspectCommands(
165188 urls : opts . urls ? true : undefined ,
166189 mode,
167190 profile,
191+ ...( request . timeoutMs === undefined ? { } : { timeoutMs : request . timeoutMs } ) ,
168192 } ;
169- const result = await callBrowserRequest < SnapshotResult > ( parent , {
193+ const result = await callBrowserRequest < SnapshotResult > ( request . parent , {
170194 method : "GET" ,
171195 path : "/snapshot" ,
172196 query,
0 commit comments