Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion front_end/panels/emulation/DeviceModeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
handleAction(context: UI.Context.Context, actionId: string): boolean {
switch (actionId) {
case 'emulation.capture-screenshot':
return DeviceModeWrapper.instance().captureScreenshot();
if (deviceModeWrapperInstance) {
return DeviceModeWrapper.instance().captureScreenshot();
}
void captureScreenshotDirect();
return true;

case 'emulation.capture-node-screenshot': {
const node = context.flavor(SDK.DOMModel.DOMNode);
Expand Down Expand Up @@ -164,3 +168,21 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
return false;
}
}

async function captureScreenshotDirect(): Promise<void> {
const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
const screenCaptureModel = target?.model(SDK.ScreenCaptureModel.ScreenCaptureModel);
if (!screenCaptureModel) {
return;
}
const screenshot = await screenCaptureModel.captureScreenshot(
'png' as Protocol.Page.CaptureScreenshotRequestFormat, 100,
SDK.ScreenCaptureModel.ScreenshotMode.FROM_VIEWPORT);
if (!screenshot) {
return;
}
const link = document.createElement('a');
link.download = 'screenshot.png';
link.href = 'data:image/png;base64,' + screenshot;
link.click();
}
3 changes: 2 additions & 1 deletion front_end/panels/emulation/emulation-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ UI.ActionRegistration.registerActionExtension({
const Emulation = await loadEmulationModule();
return new Emulation.DeviceModeWrapper.ActionDelegate();
},
condition: Root.Runtime.conditions.canDock,
// [RN] Available without docking for React Native targets.
// condition: Root.Runtime.conditions.canDock,
title: i18nLazyString(UIStrings.captureScreenshot),
});

Expand Down
Loading