File tree Expand file tree Collapse file tree
front_end/panels/emulation Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,7 +110,11 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
110110 handleAction ( context : UI . Context . Context , actionId : string ) : boolean {
111111 switch ( actionId ) {
112112 case 'emulation.capture-screenshot' :
113- return DeviceModeWrapper . instance ( ) . captureScreenshot ( ) ;
113+ if ( deviceModeWrapperInstance ) {
114+ return DeviceModeWrapper . instance ( ) . captureScreenshot ( ) ;
115+ }
116+ void captureScreenshotDirect ( ) ;
117+ return true ;
114118
115119 case 'emulation.capture-node-screenshot' : {
116120 const node = context . flavor ( SDK . DOMModel . DOMNode ) ;
@@ -164,3 +168,21 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
164168 return false ;
165169 }
166170}
171+
172+ async function captureScreenshotDirect ( ) : Promise < void > {
173+ const target = SDK . TargetManager . TargetManager . instance ( ) . primaryPageTarget ( ) ;
174+ const screenCaptureModel = target ?. model ( SDK . ScreenCaptureModel . ScreenCaptureModel ) ;
175+ if ( ! screenCaptureModel ) {
176+ return ;
177+ }
178+ const screenshot = await screenCaptureModel . captureScreenshot (
179+ 'png' as Protocol . Page . CaptureScreenshotRequestFormat , 100 ,
180+ SDK . ScreenCaptureModel . ScreenshotMode . FROM_VIEWPORT ) ;
181+ if ( ! screenshot ) {
182+ return ;
183+ }
184+ const link = document . createElement ( 'a' ) ;
185+ link . download = 'screenshot.png' ;
186+ link . href = 'data:image/png;base64,' + screenshot ;
187+ link . click ( ) ;
188+ }
Original file line number Diff line number Diff line change @@ -104,7 +104,8 @@ UI.ActionRegistration.registerActionExtension({
104104 const Emulation = await loadEmulationModule ( ) ;
105105 return new Emulation . DeviceModeWrapper . ActionDelegate ( ) ;
106106 } ,
107- condition : Root . Runtime . conditions . canDock ,
107+ // [RN] Available without docking for React Native targets.
108+ // condition: Root.Runtime.conditions.canDock,
108109 title : i18nLazyString ( UIStrings . captureScreenshot ) ,
109110} ) ;
110111
You can’t perform that action at this time.
0 commit comments