MCPcopy
hub / github.com/marimo-team/marimo / getImageDataUrlForCell

Function getImageDataUrlForCell

frontend/src/utils/download.ts:73–108  ·  view source on GitHub ↗
(
  cellId: CellId,
)

Source from the content-addressed store, hash-verified

71 * @returns The PNG as a data URL, or undefined if the cell element wasn't found
72 */
73export async function getImageDataUrlForCell(
74 cellId: CellId,
75): Promise<string | undefined> {
76 const element = findElementForCell(cellId);
77 if (!element) {
78 return;
79 }
80
81 // TODO: This doesn't handle external iframes + normal elements together (eg. in vstack).
82 // It will return the iframe only
83 const externalIframeDataUrl = await captureExternalIframes(element);
84 if (externalIframeDataUrl) {
85 return externalIframeDataUrl;
86 }
87
88 const startTime = Date.now();
89 const dataUrl = await toPng(element, {
90 extraStyleContent: HIDE_SCROLLBAR_STYLES,
91 // Add these styles so the element output is not clipped
92 // Width can be clipped since pdf has limited width
93 style: {
94 maxHeight: "none",
95 overflow: "visible",
96 },
97 height: element.scrollHeight,
98 });
99 const timeTaken = Date.now() - startTime;
100 if (timeTaken > THRESHOLD_TIME_MS) {
101 Logger.debug(
102 "toPng operation for element",
103 element,
104 `took ${timeTaken} ms (exceeds threshold)`,
105 );
106 }
107 return dataUrl;
108}
109
110/**
111 * Download a cell output as a PNG image file.

Callers 3

download.test.tsxFile · 0.90
useEnrichCellOutputsFunction · 0.90

Calls 5

captureExternalIframesFunction · 0.90
toPngFunction · 0.90
findElementForCellFunction · 0.85
nowMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…