Skip to content

Commit f2930fc

Browse files
author
Gurasuraisu
committed
Fix
2 parents 3aacd75 + bf09242 commit f2930fc

3 files changed

Lines changed: 58 additions & 82 deletions

File tree

assets/gurapp/api/gurasuraisu-api.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/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';

js/apps/window-manager.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,31 +1836,21 @@ function createCompositeScreenshot() {
18361836
return;
18371837
}
18381838

1839-
let parentDataUrl;
1840-
if (isMobile) {
1841-
const parentCanvas = await html2canvas(document.body, {
1842-
useCORS: true,
1843-
logging: false,
1844-
ignoreElements: (el) => el.tagName === 'IFRAME'
1845-
});
1846-
parentDataUrl = parentCanvas.toDataURL();
1847-
} else {
1848-
parentDataUrl = await modernScreenshot.domToJpeg(document.body, {
1849-
filter: (node) => {
1850-
if (node.nodeType === 1) {
1851-
if (node.tagName === 'IFRAME') return false;
1852-
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1853-
try {
1854-
const url = new URL(node.src, window.location.href);
1855-
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1856-
} catch(e) {}
1857-
}
1839+
const parentDataUrl = await modernScreenshot.domToJpeg(document.body, {
1840+
filter: (node) => {
1841+
if (node.nodeType === 1) {
1842+
if (node.tagName === 'IFRAME') return false;
1843+
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1844+
try {
1845+
const url = new URL(node.src, window.location.href);
1846+
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1847+
} catch(e) {}
18581848
}
1859-
return true;
1860-
},
1861-
quality: 1.0 // Keep high quality for the base composition step
1862-
});
1863-
}
1849+
}
1850+
return true;
1851+
},
1852+
quality: 1.0 // Keep high quality for the base composition step
1853+
});
18641854

18651855
const iframeListener = (event) => {
18661856
if (event.source === iframe.contentWindow && event.data.type === 'screenshot-response') {

js/waves.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -565,40 +565,30 @@ async function handleRemoteCommand(payload, peerId) {
565565
} catch (e) {
566566
console.error("[Waves] System screenshot failed:", e);
567567
}
568-
} else {
568+
} else if (window.modernScreenshot) {
569569
// Fallback
570570
try {
571571
const isLight = document.body.classList.contains('light-theme');
572+
const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
572573
const bgColor = isLight ? '#ffffff' : '#000000';
573574

574-
let imgData;
575-
if (isMobileDevice() && window.html2canvas) {
576-
const canvas = await html2canvas(document.body, {
577-
useCORS: true,
578-
logging: false,
579-
ignoreElements: (el) => el.id === 'ai-assistant-overlay',
580-
backgroundColor: bgColor
581-
});
582-
imgData = canvas.toDataURL('image/jpeg', 0.4);
583-
} else if (window.modernScreenshot) {
584-
imgData = await modernScreenshot.domToJpeg(document.body, {
585-
filter: (node) => {
586-
if (node.nodeType === 1) {
587-
if (node.id === 'ai-assistant-overlay') return false;
588-
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
589-
try {
590-
const url = new URL(node.src, window.location.href);
591-
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
592-
} catch(e) {}
593-
}
575+
const imgData = await modernScreenshot.domToJpeg(document.body, {
576+
filter: (node) => {
577+
if (node.nodeType === 1) {
578+
if (node.id === 'ai-assistant-overlay') return false;
579+
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
580+
try {
581+
const url = new URL(node.src, window.location.href);
582+
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
583+
} catch(e) {}
594584
}
595-
return true;
596-
},
597-
backgroundColor: bgColor,
598-
quality: 0.4
599-
});
600-
}
601-
if (imgData) wavesSend({ type: 'screenshot', data: imgData }, peerId);
585+
}
586+
return true;
587+
},
588+
backgroundColor: bgColor,
589+
quality: 0.4
590+
});
591+
wavesSend({ type: 'screenshot', data: imgData }, peerId);
602592
} catch (e) {
603593
console.error("[Waves] Fallback screenshot failed:", e);
604594
}

0 commit comments

Comments
 (0)