@@ -1637,6 +1637,10 @@ window.addEventListener('message', async (event) => {
16371637 case 'contrastUpdate' :
16381638 document . documentElement . classList . toggle ( 'gurasuraisu-high-contrast' , data . enabled ) ;
16391639 break ;
1640+ case 'performanceProfileUpdate' :
1641+ window . systemPerformanceScore = data . score ;
1642+ window . isLowEndDevice = ( data . score <= 2 ) ;
1643+ break ;
16401644 case 'sunUpdate' :
16411645 document . documentElement . style . setProperty ( '--sun-shadow' , data . shadow ) ;
16421646 document . documentElement . style . setProperty ( '--sun-shadow-strong' , data . shadowStrong ) ;
@@ -1781,8 +1785,12 @@ window.addEventListener('message', async (event) => {
17811785
17821786 // --- Handles screenshot requests from the parent ---
17831787 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+
17841791 // Helper function to perform the capture
17851792 const doCapture = async ( ) => {
1793+ // Save current shadow state to prevent artifacts
17861794 const root = document . documentElement ;
17871795 const originalShadow = root . style . getPropertyValue ( '--sun-shadow' ) ;
17881796 const originalShadowStrong = root . style . getPropertyValue ( '--sun-shadow-strong' ) ;
@@ -1798,19 +1806,29 @@ window.addEventListener('message', async (event) => {
17981806 const bgColor = isLight ? '#ffffff' : '#000000' ;
17991807
18001808 // Generate the screenshot of the app's content
1801- const screenshotDataUrl = await modernScreenshot . domToJpeg ( document . body , {
1802- backgroundColor : bgColor , // Explicitly set background
1803- quality : 0.5 ,
1804- filter : ( node ) => {
1805- if ( node . nodeType === 1 && ( node . tagName === 'IMG' || node . tagName === 'VIDEO' ) && node . src && ! node . src . startsWith ( 'data:' ) && ! node . src . startsWith ( 'blob:' ) ) {
1806- try {
1807- const url = new URL ( node . src , window . location . href ) ;
1808- if ( url . origin !== window . location . origin && ! node . crossOrigin ) return false ;
1809- } catch ( e ) { }
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 ;
18101829 }
1811- return true ;
1812- }
1813- } ) ;
1830+ } ) ;
1831+ }
18141832
18151833 // Send the generated screenshot data back to the parent
18161834 window . parent . postMessage ( {
@@ -1826,13 +1844,15 @@ window.addEventListener('message', async (event) => {
18261844 }
18271845 } ;
18281846
1829- // Check if modern-screenshot is loaded
1830- if ( typeof modernScreenshot === 'undefined' ) {
1831- // Inject it dynamically
1847+ if ( _isMobile && typeof html2canvas !== 'function' ) {
1848+ const script = document . createElement ( 'script' ) ;
1849+ script . src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js' ;
1850+ script . onload = doCapture ;
1851+ document . head . appendChild ( script ) ;
1852+ } else if ( ! _isMobile && typeof modernScreenshot === 'undefined' ) {
18321853 const script = document . createElement ( 'script' ) ;
18331854 script . src = 'https://cdn.jsdelivr.net/npm/modern-screenshot@4.6.8/dist/index.min.js' ;
18341855 script . onload = doCapture ;
1835- script . onerror = ( ) => console . error ( "Failed to load modern-screenshot for Gurapp" ) ;
18361856 document . head . appendChild ( script ) ;
18371857 } else {
18381858 doCapture ( ) ;
0 commit comments