Integration, or “embed mode” is used for cases where the storage of the diagram is taken care of by a host application, and diagrams.net is used for diagram editing. In this case, diagrams.net is used inside an iframe or window with special URL parameters, and is remote controlled using the HTML5 Messaging API. Use embed.diagrams.net only for embed mode.
Depending on the requirements, a PNG or SVG image or the XML for the diagram can be used as the storage format. Consider the following when picking the storage format:
The storage can be any persistence mechanism. The image or XML file can be stored and used in the output of the host application, such as an image tag, SVG DOM or HTML viewer. Authentication, file descriptors, revisions etc must be handled by the host application. All communication between the host application and diagrams.net happens on the client-side.
The protocol specification describes the full messaging API.
The basic flow of the protocol is:
init eventload actionsave/exit eventIn some cases, additional steps may be required to check for a draft state or to export the diagram as an image. Special messages are available in the protocol to show draft states or a template dialog.
Fonts, colors, default styles, libraries, CSS and more can be configured to match the environment and style of the host application by using the configure=1 URL parameter. See localstorage-svg.html.
JavaScript API for editing embedded SVG and PNG images in an HTML page.
diagram-editor.js - Reusable JavaScript API wrapper for the draw.io editorhelloworld.html - Minimal example (live)javascript.html - Advanced example with multiple formats (live)collapsed.html - Collapsible diagram exampleEditing with embedInline mode and adapting embedded SVG images to dark mode.
inline.js - Inline editing implementation with dark mode supportinline.html - Example page (live)inline.drawio.svg - Sample SVG diagramSaving and loading diagrams to/from HTML5 local storage.
localstorage.html - PNG format (live)localstorage-svg.html - SVG format with hyperlink support (live)localfile.html - Self-modifying local file (live)Roundtrip editing of diagrams stored on a WebDAV server.
edit-diagram.html - Standalone editing pageself-editing.svg - Self-editing SVG file with embedded PNGself-editing.html - Self-editing HTML with embedded diagramsself-editing-embed.html - Self-editing HTML using embed.jsself-editing-image.html - Self-editing HTML using img tagembed.js - Double-click handler for editing drawio imagesA template Chrome extension (Manifest V3) for adding draw.io diagram support to any web application. Based on a production integration. Includes diagram detection, inline editor, dark mode support, and placeholder save handler ready to be connected to your app’s API.
contentScript.js - Main integration logicpopup.html / popup.js - Extension popup UImanifest.json - Extension manifest