File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 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 (
117117 }
118118 }
119119
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+
120131 const document = dedent ( `
121132 <!DOCTYPE html>
122133 <html>
@@ -147,11 +158,6 @@ export const renderAsync = async (
147158 scaleFactor,
148159 timestamp: new Date().toISOString()
149160 });
150-
151- // const htmlElement = document.querySelector("html");
152- // if (htmlElement) {
153- // htmlElement.style.transform = "scale(" + scaleFactor + ") translateX(" + horizontalPadding + "px)";
154- // }
155161 } catch (err) {
156162 console.error("Error in scaleToFit:", err);
157163 }
You can’t perform that action at this time.
0 commit comments