File tree 1 file changed +11
-5
lines changed
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,17 @@ export const renderAsync = async (
117
117
}
118
118
}
119
119
120
+ // Add onerror attribute to all <link rel="stylesheet"> tags.
121
+ // This ensures that if a stylesheet link fails (due to an invalid URL or CORS issues),
122
+ // it gets removed, so that the iframe content can still load.
123
+ extractedHeadContents = extractedHeadContents . replace (
124
+ / < l i n k ( [ ^ > ] * r e l = [ " ' ] s t y l e s h e e t [ " ' ] [ ^ > ] * ) > / gi,
125
+ ( match , p1 ) => {
126
+ if ( match . includes ( 'onerror=' ) ) return match ;
127
+ return `<link${ p1 } onerror="console.error('Failed to load stylesheet:', this.href); this.onerror=null;this.remove();">` ;
128
+ }
129
+ ) ;
130
+
120
131
const document = dedent ( `
121
132
<!DOCTYPE html>
122
133
<html>
@@ -147,11 +158,6 @@ export const renderAsync = async (
147
158
scaleFactor,
148
159
timestamp: new Date().toISOString()
149
160
});
150
-
151
- // const htmlElement = document.querySelector("html");
152
- // if (htmlElement) {
153
- // htmlElement.style.transform = "scale(" + scaleFactor + ") translateX(" + horizontalPadding + "px)";
154
- // }
155
161
} catch (err) {
156
162
console.error("Error in scaleToFit:", err);
157
163
}
You can’t perform that action at this time.
0 commit comments