releasebird-javascript-sdk 1.0.68 → 1.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -586,7 +586,8 @@ export default class RbirdScreenshotManager {
586
586
  }
587
587
 
588
588
  /**
589
- * Convert CSS url() references to data URLs with resizing
589
+ * Convert CSS url() references to data URLs
590
+ * Handles both images (with resizing) and fonts (without resizing)
590
591
  */
591
592
  async loadCSSUrlResources(cssText, basePath) {
592
593
  const urlRegex = /url\(['"]?([^'"()]+)['"]?\)/g;
@@ -597,32 +598,101 @@ export default class RbirdScreenshotManager {
597
598
  matches.push(match);
598
599
  }
599
600
 
601
+ // Font file extensions
602
+ const fontExtensions = ['.woff2', '.woff', '.ttf', '.eot', '.otf'];
603
+ // Image file extensions
604
+ const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp'];
605
+
600
606
  for (const match of matches) {
601
607
  const url = match[1];
602
608
 
603
- // Skip if already a data URL or absolute URL
604
- if (url.startsWith('data:') || url.startsWith('http')) {
609
+ // Skip if already a data URL
610
+ if (url.startsWith('data:')) {
605
611
  continue;
606
612
  }
607
613
 
614
+ // Determine file type
615
+ const urlLower = url.toLowerCase();
616
+ const isFont = fontExtensions.some(ext => urlLower.includes(ext));
617
+ const isImage = imageExtensions.some(ext => urlLower.includes(ext));
618
+
608
619
  try {
609
- const fullURL = new URL(url, basePath + '/').href;
610
- const dataURL = await this.fetchImageAsDataURL(fullURL);
620
+ let fullURL;
621
+
622
+ // Handle both relative and absolute URLs
623
+ if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) {
624
+ fullURL = url.startsWith('//') ? 'https:' + url : url;
625
+ } else {
626
+ fullURL = new URL(url, basePath + '/').href;
627
+ }
628
+
629
+ console.log(`[Screenshot] Processing CSS resource: ${fullURL} (font: ${isFont}, image: ${isImage})`);
630
+
631
+ const dataURL = await this.fetchResourceAsDataURL(fullURL);
632
+
611
633
  if (dataURL) {
612
- // Resize CSS background images too
613
- const resizedDataURL = await this.resizeImage(dataURL, 500, 500, 0.7);
614
- if (resizedDataURL) {
615
- cssText = cssText.replace(match[0], `url(${resizedDataURL})`);
634
+ if (isFont) {
635
+ // Don't resize fonts - use as-is
636
+ cssText = cssText.split(match[0]).join(`url(${dataURL})`);
637
+ console.log(`[Screenshot] Embedded font: ${url}`);
638
+ } else if (isImage) {
639
+ // Resize images to reduce payload
640
+ try {
641
+ const resizedDataURL = await this.resizeImage(dataURL, 500, 500, 0.7);
642
+ if (resizedDataURL) {
643
+ cssText = cssText.split(match[0]).join(`url(${resizedDataURL})`);
644
+ }
645
+ } catch (resizeErr) {
646
+ // If resize fails, use original
647
+ cssText = cssText.split(match[0]).join(`url(${dataURL})`);
648
+ }
649
+ } else {
650
+ // Unknown type - embed as-is
651
+ cssText = cssText.split(match[0]).join(`url(${dataURL})`);
616
652
  }
617
653
  }
618
654
  } catch (err) {
619
- console.warn('[Screenshot] Failed to convert CSS url:', url, err);
655
+ console.warn('[Screenshot] Failed to convert CSS url:', url, err.message);
620
656
  }
621
657
  }
622
658
 
623
659
  return cssText;
624
660
  }
625
661
 
662
+ /**
663
+ * Fetch any resource and convert to data URL
664
+ * Works for images, fonts, and other binary files
665
+ */
666
+ fetchResourceAsDataURL(url) {
667
+ return new Promise((resolve, reject) => {
668
+ const xhr = new XMLHttpRequest();
669
+ xhr.onload = function() {
670
+ if (xhr.status === 200) {
671
+ const reader = new FileReader();
672
+ reader.onloadend = function() {
673
+ resolve(reader.result);
674
+ };
675
+ reader.onerror = function() {
676
+ reject(new Error('Failed to read resource'));
677
+ };
678
+ reader.readAsDataURL(xhr.response);
679
+ } else {
680
+ reject(new Error(`HTTP ${xhr.status}`));
681
+ }
682
+ };
683
+ xhr.onerror = function() {
684
+ reject(new Error('Failed to fetch resource'));
685
+ };
686
+ xhr.ontimeout = function() {
687
+ reject(new Error('Request timeout'));
688
+ };
689
+ xhr.open('GET', url);
690
+ xhr.responseType = 'blob';
691
+ xhr.timeout = 10000; // 10 second timeout
692
+ xhr.send();
693
+ });
694
+ }
695
+
626
696
 
627
697
  /**
628
698
  * Compress string using gzip
@@ -350,7 +350,7 @@ export default class RbirdWebsiteWidget {
350
350
  }
351
351
 
352
352
  updateIframe(iframeSrc) {
353
- this.widgetContent.innerHTML = `<iframe src=${iframeSrc} class="rbird-content-iframe" scrolling="yes" title="Releasebird" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe>`;
353
+ this.widgetContent.innerHTML = `<iframe src=${iframeSrc} class="rbird-content-iframe" scrolling="yes" title="Releasebird" allow="autoplay; encrypted-media; fullscreen; microphone;" frameborder="0"></iframe>`;
354
354
  this.iframe = this.widgetContent.firstChild;
355
355
  this.iframe.scrolling="no";
356
356
  }