From d0ca2ebeedf4cb67cca9d85427d1a2e582ec01f3 Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Tue, 17 Mar 2026 15:40:39 +0000
Subject: [PATCH 1/2] feat: add UIHTMLDevTools for injecting Eruda into uihtml
components
Added a new class UIHTMLDevTools to inject the Eruda developer console into
matlab.ui.control.HTML components. Like ConsoleErrorRerouter, it works by
creating a temporary copy of the user's HTML and injecting a `");
+ testCase.verifySubstring(content, "");
+
+ % Copied eruda.js exists in the HTML file's directory after construction
+ targetDir = fileparts(testCase.FixtureHtml);
+ pErudaDest = fullfile(targetDir, "eruda.js");
+ testCase.verifyTrue(isfile(pErudaDest));
+ end % function testInjection
+
+ function testCleanup(testCase)
+ devTools = UIHTMLDevTools(testCase.Component);
+ testCase.DevTools = devTools;
+
+ tempFile = string(testCase.Component.HTMLSource);
+ targetDir = fileparts(testCase.FixtureHtml);
+ pErudaDest = fullfile(targetDir, "eruda.js");
+
+ % Perform cleanup by deleting the object
+ delete(devTools);
+
+ % Temp file and copied eruda.js are both deleted on destruction
+ testCase.verifyFalse(isfile(tempFile));
+ testCase.verifyFalse(isfile(pErudaDest));
+
+ % Original HTMLSource is restored on destruction
+ testCase.verifyEqual(string(testCase.Component.HTMLSource), testCase.FixtureHtml);
+ end % function testCleanup
+ end % methods (Test)
+end % classdef tUIHTMLDevTools
\ No newline at end of file
diff --git a/toolbox/UIHTMLDevTools.m b/toolbox/UIHTMLDevTools.m
new file mode 100644
index 0000000..27142a7
--- /dev/null
+++ b/toolbox/UIHTMLDevTools.m
@@ -0,0 +1,151 @@
+classdef UIHTMLDevTools < handle
+ % UIHTMLDevTools Injects Eruda dev tools into a uihtml component.
+ %
+ % obj = UIHTMLDevTools(uihtmlComp) creates a dev tools injector for the given
+ % uihtml component.
+
+ properties
+ % Toggles the dev tools injection on/off. Default: true.
+ Enabled (1,1) logical = true
+ end
+
+ properties (Access = private)
+ % Reference to the uihtml component.
+ HtmlComponent
+ % Backup of the original HTMLSource.
+ OriginalHTMLSource string = ""
+ % Path to the temporary injected HTML file.
+ TempHTMLPath string = ""
+ end
+
+ methods
+ function obj = UIHTMLDevTools(uihtmlComp)
+ % UIHTMLDevTools Constructor
+ %
+ % obj = UIHTMLDevTools(uihtmlComp) attaches the dev tools to
+ % the provided uihtml component.
+ arguments
+ uihtmlComp (1,1) matlab.ui.control.HTML
+ end
+
+ obj.HtmlComponent = uihtmlComp;
+
+ % Handle dev tools injection if HTMLSource is provided
+ if strlength(string(uihtmlComp.HTMLSource)) > 0
+ obj.injectEruda();
+ end
+ end % Constructor
+
+ function delete(obj)
+ % delete Destructor
+ %
+ % Cleans up temporary files.
+ obj.removeEruda();
+ end % function delete
+ end % methods
+
+ methods (Access = private)
+ function injectEruda(obj)
+ % injectEruda Injects Eruda into a temporary copy of the HTML.
+ source = string(obj.HtmlComponent.HTMLSource);
+ obj.OriginalHTMLSource = source;
+
+ % If it's a URL, we cannot inject the shim by file modification.
+ if startsWith(source, "http://") || startsWith(source, "https://")
+ error("uihtmlDevTools:UrlHTMLSource", ...
+ "URLs are not supported by UIHTMLDevTools");
+ end
+
+ % Read original HTML
+ if isfile(source)
+ htmlContent = fileread(source);
+ else
+ error("uihtmlDevTools:InvalidHTMLSource", ...
+ "HTML source must be a file.");
+ end
+
+ % Copy eruda.js to the target directory
+ [targetDir, name, ext] = fileparts(source);
+ if isempty(targetDir)
+ targetDir = pwd;
+ end
+
+ dSelf = fileparts(mfilename("fullpath"));
+ pErudaSrc = fullfile(dSelf, "vendor", "eruda", "eruda.js");
+ pErudaDest = fullfile(targetDir, "eruda.js");
+
+ try
+ copyfile(pErudaSrc, pErudaDest);
+ catch
+ error("uihtmlDevTools:ErudaCopyFailure", ...
+ "Failed to copy eruda.js to:\n%s", pErudaDest);
+ end
+
+ % Prepare the script block
+ scriptBlock = "" + newline + ...
+ "";
+
+ % Insert just before