diff --git a/daemon/daemon.go b/daemon/daemon.go index fce3a4f..ec1a0a1 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -13059,20 +13059,20 @@ func (d *Daemon) extractDiviStructure(tabID string, timeout int) (*DiviStructure } // JavaScript to extract Divi structure - jsCode := ` - (function() { - const result = { - url: window.location.href, - sections: [], - metadata: { - extraction_date: new Date().toISOString(), - accuracy: "60-70% (approximation from CSS classes)", - limitations: "Cannot access original Divi shortcode/JSON or builder settings" - } - }; + // Note: page.Eval expects a function expression, not an IIFE + jsCode := `() => { + const result = { + url: window.location.href, + sections: [], + metadata: { + extraction_date: new Date().toISOString(), + accuracy: "60-70% (approximation from CSS classes)", + limitations: "Cannot access original Divi shortcode/JSON or builder settings" + } + }; - // Find all Divi sections - const sections = document.querySelectorAll('.et_pb_section, .et_section_specialty, .et_pb_fullwidth_section'); + // Find all Divi sections + const sections = document.querySelectorAll('.et_pb_section, .et_section_specialty, .et_pb_fullwidth_section'); sections.forEach((section, sectionIndex) => { const sectionData = { @@ -13198,8 +13198,7 @@ func (d *Daemon) extractDiviStructure(tabID string, timeout int) (*DiviStructure }); return result; - })(); - ` + }` // Execute JavaScript with timeout var resultData interface{} @@ -13265,53 +13264,52 @@ func (d *Daemon) extractDiviImages(tabID string, timeout int) ([]DiviImage, erro } // JavaScript to extract images - jsCode := ` - (function() { - const images = []; - let imageIndex = 0; + // Note: page.Eval expects a function expression, not an IIFE + jsCode := `() => { + const images = []; + let imageIndex = 0; - // Extract regular images - document.querySelectorAll('img').forEach((img) => { - if (img.src && img.src !== '') { + // Extract regular images + document.querySelectorAll('img').forEach((img) => { + if (img.src && img.src !== '') { + images.push({ + url: img.src, + alt: img.alt || '', + title: img.title || '', + width: img.naturalWidth || img.width || 0, + height: img.naturalHeight || img.height || 0, + context: 'image ' + imageIndex, + is_background: false + }); + imageIndex++; + } + }); + + // Extract background images + document.querySelectorAll('*').forEach((element) => { + const styles = window.getComputedStyle(element); + const bgImage = styles.backgroundImage; + + if (bgImage && bgImage !== 'none' && !bgImage.includes('gradient')) { + // Extract URL from background-image + const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/); + if (urlMatch && urlMatch[1]) { images.push({ - url: img.src, - alt: img.alt || '', - title: img.title || '', - width: img.naturalWidth || img.width || 0, - height: img.naturalHeight || img.height || 0, - context: 'image ' + imageIndex, - is_background: false + url: urlMatch[1], + alt: '', + title: '', + width: 0, + height: 0, + context: 'background ' + imageIndex, + is_background: true }); imageIndex++; } - }); + } + }); - // Extract background images - document.querySelectorAll('*').forEach((element) => { - const styles = window.getComputedStyle(element); - const bgImage = styles.backgroundImage; - - if (bgImage && bgImage !== 'none' && !bgImage.includes('gradient')) { - // Extract URL from background-image - const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/); - if (urlMatch && urlMatch[1]) { - images.push({ - url: urlMatch[1], - alt: '', - title: '', - width: 0, - height: 0, - context: 'background ' + imageIndex, - is_background: true - }); - imageIndex++; - } - } - }); - - return images; - })(); - ` + return images; + }` // Execute JavaScript with timeout var resultData interface{} @@ -13377,21 +13375,21 @@ func (d *Daemon) extractDiviContent(tabID string, timeout int) (*DiviContent, er } // JavaScript to extract content - jsCode := ` - (function() { - const result = { - url: window.location.href, - modules: [], - images: [], - metadata: { - extraction_date: new Date().toISOString(), - total_modules: 0, - total_images: 0 - } - }; + // Note: page.Eval expects a function expression, not an IIFE + jsCode := `() => { + const result = { + url: window.location.href, + modules: [], + images: [], + metadata: { + extraction_date: new Date().toISOString(), + total_modules: 0, + total_images: 0 + } + }; - // Extract all Divi modules - const modules = document.querySelectorAll('[class*="et_pb_module"]'); + // Extract all Divi modules + const modules = document.querySelectorAll('[class*="et_pb_module"]'); modules.forEach((module, index) => { const moduleData = { @@ -13458,8 +13456,7 @@ func (d *Daemon) extractDiviContent(tabID string, timeout int) (*DiviContent, er result.metadata.total_images = result.images.length; return result; - })(); - ` + }` // Execute JavaScript with timeout var resultData interface{}