Skip to content

Commit db93dd9

Browse files
committed
fix: screenshot of markdown preview via #panel-live-preview-frame
When a markdown file is open, the preview panel uses #panel-md-preview-frame instead of #panel-live-preview-frame. Redirect the selector automatically in phoenix-builder-client.js so '#panel-live-preview-frame' works for both HTML and markdown previews. Update MCP tool description to mention markdown preview support.
1 parent 6d9d802 commit db93dd9

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src-node/mcp-editor-tools.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@ function createEditorMcpServer(sdkModule, nodeConnector, clarificationAccessors)
8888
"takeScreenshot",
8989
"Take a screenshot of the Phoenix Code editor application window or the live preview within it (not a web page). " +
9090
"The editor window contains: a toolbar at the top, a file tree sidebar on the left, " +
91-
"the code editor area in the center, and optionally a live preview panel on the right " +
92-
"that renders the HTML/CSS/JS output of the currently edited file in a browser view. " +
91+
"the code editor area in the center, and optionally a live preview panel on the right. " +
92+
"The preview panel shows either an HTML/CSS/JS browser view or a rendered markdown preview " +
93+
"(when a markdown file is open, the panel shows a WYSIWYG markdown editor/viewer). " +
9394
"By default captures the entire editor window and returns the screenshot as an inline PNG image. " +
9495
"If filePath is specified, saves to that file and returns the path instead. " +
9596
"Prefer capturing specific regions using the selector parameter instead of the full window: " +
96-
"use '#panel-live-preview-frame' to capture only the live preview content, " +
97+
"use '#panel-live-preview-frame' to capture the preview panel (works for both HTML live preview and markdown preview), " +
9798
"or '.editor-holder' to capture only the code editor area. " +
9899
"Only omit the selector when you need to see the full editor application layout. " +
99100
"Note: live preview screenshots may include Phoenix toolbox overlays on selected elements. " +
100101
"Use purePreview=true to temporarily hide these overlays and render the page as it would appear in a real browser.",
101102
{
102-
selector: z.string().optional().describe("CSS selector to capture a specific element. Use '#panel-live-preview-frame' for the live preview, '.editor-holder' for the code editor."),
103+
selector: z.string().optional().describe("CSS selector to capture a specific element. Use '#panel-live-preview-frame' for the preview panel (HTML live preview or markdown preview), '.editor-holder' for the code editor."),
103104
purePreview: z.boolean().optional().describe("When true, temporarily switches to preview mode to hide element highlight overlays and toolboxes before capturing, then restores the previous mode."),
104105
filePath: z.string().optional().describe("Absolute path to save the screenshot as a PNG file. If specified, returns the file path instead of inline image data.")
105106
},

src/phoenix-builder/phoenix-builder-client.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ define(function (require, exports, module) {
4343
return;
4444
}
4545

46-
Phoenix.app.screenShotBinary(msg.selector || undefined)
46+
// If targeting live preview frame and md viewer is active, redirect to md frame
47+
let selector = msg.selector || undefined;
48+
if (selector === "#panel-live-preview-frame") {
49+
const mdFrame = document.getElementById("panel-md-preview-frame");
50+
if (mdFrame && mdFrame.offsetParent) {
51+
selector = "#panel-md-preview-frame";
52+
}
53+
}
54+
Phoenix.app.screenShotBinary(selector)
4755
.then(function (bytes) {
4856
let binary = "";
4957
const chunkSize = 8192;

0 commit comments

Comments
 (0)