diff --git a/src/index.html b/src/index.html
index e07b2c3..0cce649 100644
--- a/src/index.html
+++ b/src/index.html
@@ -16765,7 +16765,14 @@
// to whatever pixel size the wrapper ends up at.
function rebuildClipDefs(layers) {
const defsRoot = ensureGlobalClipDefs();
- const defs = defsRoot.querySelector('defs');
+ let defs = defsRoot.querySelector('defs');
+ if (!defs) {
+ // Pre-existing globalClipDefs SVG without an inner
+ // (e.g. injected by an early DOM hook or an extension). Recreate
+ // it so the rebuild doesn't crash and abort render().
+ defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
+ defsRoot.appendChild(defs);
+ }
defs.innerHTML = '';
const map = new Map();
for (const layer of layers || []) {