A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: support srcdoc screenshots (#8001)
Myles Scolnick2f95e5483157
diff --git a/.github/workflows/test_fe.yaml b/.github/workflows/test_fe.yamlindex 7885139e36..574d88a3e7 100644--- a/.github/workflows/test_fe.yaml+++ b/.github/workflows/test_fe.yaml@@ -151,6 +151,10 @@ jobs:echo "Error: vega-lite version in package.json must be exactly 6.3.1. Newer versions break numeric tooltips"exit 1fi+ if ! grep -q '"html-to-image": "1.11.13"' package.json; then+ echo "Error: html-to-image version in package.json must be exactly 1.11.13. Newer versions break matplotlib toolbars"+ exit 1+ fi- name: 📦 Buildid: builddiff --git a/frontend/package.json b/frontend/package.jsonindex dfcd701cf1..177d98fb5c 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -128,7 +128,7 @@"eslint-plugin-header": "^3.1.1","htm": "^3.1.1","html-react-parser": "^5.2.11",- "html-to-image": "^1.11.13",+ "html-to-image": "1.11.13","humanize-duration": "^3.33.2","iconify-icon": "^2.3.0","jotai": "^2.16.1",diff --git a/frontend/src/core/ai/context/providers/cell-output.ts b/frontend/src/core/ai/context/providers/cell-output.tsindex edfafbc0e4..279afbb2b2 100644--- a/frontend/src/core/ai/context/providers/cell-output.ts+++ b/frontend/src/core/ai/context/providers/cell-output.ts@@ -2,7 +2,6 @@import type { Completion } from "@codemirror/autocomplete";import type { FileUIPart } from "ai";-import { toPng } from "html-to-image";import { processOutput } from "@/components/editor/output/console/process-output";import { type NotebookState, notebookAtom } from "@/core/cells/cells";import { type CellId, CellOutputId } from "@/core/cells/ids";@@ -10,6 +9,7 @@ import { displayCellName } from "@/core/cells/names";import { isOutputEmpty } from "@/core/cells/outputs";import type { OutputMessage } from "@/core/kernel/messages";import type { JotaiStore } from "@/core/state/jotai";+import { toPng } from "@/utils/html-to-image";import { Logger } from "@/utils/Logger";import { type AIContextItem, AIContextProvider } from "../registry";import { contextToXml } from "../utils";diff --git a/frontend/src/core/export/__tests__/hooks.test.ts b/frontend/src/core/export/__tests__/hooks.test.tsindex 2d3571867e..a03d7b4f3b 100644--- a/frontend/src/core/export/__tests__/hooks.test.ts+++ b/frontend/src/core/export/__tests__/hooks.test.ts@@ -137,7 +137,13 @@ describe("useEnrichCellOutputs", () => {expect(document.getElementById).toHaveBeenCalledWith(CellOutputId.create(cellId),);- expect(toPng).toHaveBeenCalledWith(mockElement);+ expect(toPng).toHaveBeenCalledWith(+ mockElement,+ expect.objectContaining({+ filter: expect.any(Function),+ onImageErrorHandler: expect.any(Function),+ }),+ );expect(output).toEqual({[cellId]: ["image/png", mockDataUrl],});diff --git a/frontend/src/utils/__tests__/download.test.tsx b/frontend/src/utils/__tests__/download.test.tsxindex dc7a7522f5..4b85e6dfb6 100644--- a/frontend/src/utils/__tests__/download.test.tsx+++ b/frontend/src/utils/__tests__/download.test.tsx@@ -155,7 +155,13 @@ describe("getImageDataUrlForCell", () => {const result = await getImageDataUrlForCell("cell-1" as CellId);expect(result).toBe(mockDataUrl);- expect(toPng).toHaveBeenCalledWith(mockElement);+ expect(toPng).toHaveBeenCalledWith(+ mockElement,+ expect.objectContaining({+ filter: expect.any(Function),+ onImageErrorHandler: expect.any(Function),+ }),+ );});it("should add printing classes before capture when enablePrintMode is true", async () => {@@ -352,7 +358,13 @@ describe("downloadHTMLAsImage", () => {await downloadHTMLAsImage({ element: mockElement, filename: "test" });- expect(toPng).toHaveBeenCalledWith(mockElement);+ expect(toPng).toHaveBeenCalledWith(+ mockElement,+ expect.objectContaining({+ filter: expect.any(Function),+ onImageErrorHandler: expect.any(Function),+ }),+ );expect(mockAnchor.href).toBe(mockDataUrl);expect(mockAnchor.download).toBe("test.png");expect(mockAnchor.click).toHaveBeenCalled();@@ -488,7 +500,13 @@ describe("downloadCellOutputAsImage", () => {await downloadCellOutputAsImage("cell-1" as CellId, "result");- expect(toPng).toHaveBeenCalledWith(mockElement);+ expect(toPng).toHaveBeenCalledWith(+ mockElement,+ expect.objectContaining({+ filter: expect.any(Function),+ onImageErrorHandler: expect.any(Function),+ }),+ );expect(mockAnchor.download).toBe("result.png");});diff --git a/frontend/src/utils/download.ts b/frontend/src/utils/download.tsindex 0dae76d3ca..d3565ed995 100644--- a/frontend/src/utils/download.ts+++ b/frontend/src/utils/download.ts@@ -1,11 +1,12 @@/* Copyright 2026 Marimo. All rights reserved. */-import { toPng } from "html-to-image";+import { toast } from "@/components/ui/use-toast";import { type CellId, CellOutputId } from "@/core/cells/ids";import { getRequestClient } from "@/core/network/requests";import { Filenames } from "@/utils/filenames";import { Paths } from "@/utils/paths";import { prettyError } from "./errors";+import { toPng } from "./html-to-image";import { Logger } from "./Logger";/**diff --git a/frontend/src/utils/html-to-image.ts b/frontend/src/utils/html-to-image.tsnew file mode 100644index 0000000000..2911102092--- /dev/null+++ b/frontend/src/utils/html-to-image.ts@@ -0,0 +1,41 @@+/* Copyright 2026 Marimo. All rights reserved. */+import { toPng as htmlToImageToPng } from "html-to-image";+import { Logger } from "./Logger";++export type HtmlToImageOptions = Parameters<typeof htmlToImageToPng>[1];++/**+ * Default options for html-to-image conversions.+ * These handle common edge cases like filtering out toolbars and logging errors.+ */+export const defaultHtmlToImageOptions: HtmlToImageOptions = {+ filter: (node) => {+ try {+ if ("classList" in node) {+ // Filter out matplotlib toolbars+ return !node.classList.contains("mpl-toolbar");+ }+ return true;+ } catch (error) {+ Logger.error("Error filtering node:", error);+ return true;+ }+ },+ onImageErrorHandler: (event) => {+ Logger.error("Error loading image:", event);+ },+};++/**+ * Convert an HTML element to a PNG data URL.+ * This is a wrapper around html-to-image's toPng with default options applied.+ */+export function toPng(+ element: HTMLElement,+ options?: HtmlToImageOptions,+): Promise<string> {+ return htmlToImageToPng(element, {+ ...defaultHtmlToImageOptions,+ ...options,+ });+}diff --git a/frontend/vite.config.mts b/frontend/vite.config.mtsindex 3fdeb52474..1c8fa585db 100644--- a/frontend/vite.config.mts+++ b/frontend/vite.config.mts@@ -233,6 +233,14 @@ export default defineConfig({target: TARGET,changeOrigin: true,},+ "/mpl": {+ target: TARGET,+ ws: true,+ changeOrigin: true,+ headers: {+ origin: TARGET,+ },+ },"/custom.css": {target: TARGET,changeOrigin: true,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b8a7be8a88..28cdf634d7 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -362,7 +362,7 @@ importers:specifier: ^5.2.11version: 5.2.11(@types/[email protected])([email protected])html-to-image:- specifier: ^1.11.13+ specifier: 1.11.13version: 1.11.13(patch_hash=eced1b085df9a49a9c81d730049c8285c754fc89e68672c14722337c75d72eaf)humanize-duration:specifier: ^3.33.2