@@ -1785,50 +1785,33 @@ window.addEventListener('message', async (event) => {
17851785
17861786 // --- Handles screenshot requests from the parent ---
17871787 case 'request-screenshot' :
1788- if ( window . isLowEndDevice ) return ; // Do not take screenshots on very low-end devices
1789- const _isMobile = / A n d r o i d | w e b O S | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i / i. test ( navigator . userAgent ) ;
1790-
17911788 // Helper function to perform the capture
17921789 const doCapture = async ( ) => {
17931790 // Save current shadow state to prevent artifacts
17941791 const root = document . documentElement ;
17951792 const originalShadow = root . style . getPropertyValue ( '--sun-shadow' ) ;
17961793 const originalShadowStrong = root . style . getPropertyValue ( '--sun-shadow-strong' ) ;
1797-
1798- // Temporarily hide shadows
17991794 root . style . setProperty ( '--sun-shadow' , 'none' ) ;
18001795 root . style . setProperty ( '--sun-shadow-strong' , 'none' ) ;
18011796
18021797 try {
1803- // Determine theme-based background color
1804- // Gurapps sync the 'light-theme' class from the parent
18051798 const isLight = document . body . classList . contains ( 'light-theme' ) ;
18061799 const bgColor = isLight ? '#ffffff' : '#000000' ;
18071800
18081801 // Generate the screenshot of the app's content
1809- let screenshotDataUrl ;
1810- if ( _isMobile ) {
1811- const canvas = await html2canvas ( document . body , {
1812- useCORS : true ,
1813- logging : false ,
1814- backgroundColor : bgColor
1815- } ) ;
1816- screenshotDataUrl = canvas . toDataURL ( 'image/jpeg' , 0.5 ) ;
1817- } else {
1818- screenshotDataUrl = await modernScreenshot . domToJpeg ( document . body , {
1819- backgroundColor : bgColor , // Explicitly set background
1820- quality : 0.5 ,
1821- filter : ( node ) => {
1822- if ( node . nodeType === 1 && ( node . tagName === 'IMG' || node . tagName === 'VIDEO' ) && node . src && ! node . src . startsWith ( 'data:' ) && ! node . src . startsWith ( 'blob:' ) ) {
1823- try {
1824- const url = new URL ( node . src , window . location . href ) ;
1825- if ( url . origin !== window . location . origin && ! node . crossOrigin ) return false ;
1826- } catch ( e ) { }
1827- }
1828- return true ;
1802+ const screenshotDataUrl = await modernScreenshot . domToJpeg ( document . body , {
1803+ backgroundColor : bgColor , // Explicitly set background
1804+ quality : 0.5 ,
1805+ filter : ( node ) => {
1806+ if ( node . nodeType === 1 && ( node . tagName === 'IMG' || node . tagName === 'VIDEO' ) && node . src && ! node . src . startsWith ( 'data:' ) && ! node . src . startsWith ( 'blob:' ) ) {
1807+ try {
1808+ const url = new URL ( node . src , window . location . href ) ;
1809+ if ( url . origin !== window . location . origin && ! node . crossOrigin ) return false ;
1810+ } catch ( e ) { }
18291811 }
1830- } ) ;
1831- }
1812+ return true ;
1813+ }
1814+ } ) ;
18321815
18331816 // Send the generated screenshot data back to the parent
18341817 window . parent . postMessage ( {
@@ -1838,12 +1821,25 @@ window.addEventListener('message', async (event) => {
18381821 } catch ( e ) {
18391822 console . error ( "Gurapp screenshot failed:" , e ) ;
18401823 } finally {
1841- // Restore shadows
18421824 if ( originalShadow ) root . style . setProperty ( '--sun-shadow' , originalShadow ) ;
18431825 if ( originalShadowStrong ) root . style . setProperty ( '--sun-shadow-strong' , originalShadowStrong ) ;
18441826 }
18451827 } ;
18461828
1829+ const libUrl = isMobile
1830+ ? 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js'
1831+ : 'https://cdn.jsdelivr.net/npm/modern-screenshot@4.6.8/dist/index.min.js' ;
1832+ const libCheck = isMobile ? ( typeof html2canvas === 'function' ) : ( typeof modernScreenshot !== 'undefined' ) ;
1833+
1834+ if ( ! libCheck ) {
1835+ const script = document . createElement ( 'script' ) ;
1836+ script . src = libUrl ;
1837+ script . onload = doCapture ;
1838+ document . head . appendChild ( script ) ;
1839+ } else {
1840+ doCapture ( ) ;
1841+ } ;
1842+
18471843 if ( _isMobile && typeof html2canvas !== 'function' ) {
18481844 const script = document . createElement ( 'script' ) ;
18491845 script . src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js' ;
0 commit comments