From dd2608bcb02b0d051b4e7a881894a89120e2f209 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 23:31:06 +0000 Subject: [PATCH] refactor: optimize selection capture and remove dead code - Removed Node.js export from capture.js (browser-only code) - Simplified selection capture to avoid expensive getComputedStyle() calls - Added performance notes for selection clipping - Aligned content.js with capture.js implementation Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- browser-extension/scripts/capture.js | 10 ++-------- browser-extension/scripts/content.js | 25 ++++--------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/browser-extension/scripts/capture.js b/browser-extension/scripts/capture.js index d67cbc95..1e6faca3 100644 --- a/browser-extension/scripts/capture.js +++ b/browser-extension/scripts/capture.js @@ -46,6 +46,8 @@ function captureFullPage() { /** * Capture selected content from the page + * Note: For performance, selection clipping uses basic HTML structure without + * per-element computed styles. The resulting PDF will use browser default styles. * @returns {Object} Selection data with HTML, text, and metadata */ function captureSelection() { @@ -92,11 +94,3 @@ function captureSelection() { timestamp: new Date().toISOString() }; } - -// Export functions for use in other scripts -if (typeof module !== 'undefined' && module.exports) { - module.exports = { - captureFullPage, - captureSelection - }; -} diff --git a/browser-extension/scripts/content.js b/browser-extension/scripts/content.js index 3c315066..9ad788e5 100644 --- a/browser-extension/scripts/content.js +++ b/browser-extension/scripts/content.js @@ -45,6 +45,8 @@ function captureFullPage() { /** * Capture selected content from the page + * Note: For performance, uses basic HTML structure without per-element computed styles. + * The resulting PDF will use browser default styles. */ function captureSelection() { const selection = window.getSelection(); @@ -57,27 +59,6 @@ function captureSelection() { const container = document.createElement('div'); container.appendChild(range.cloneContents()); - // Get computed styles for the selection - const elements = container.querySelectorAll('*'); - elements.forEach(el => { - const computed = window.getComputedStyle(el); - // Only preserve essential styles - const essentialStyles = [ - 'font-family', 'font-size', 'font-weight', 'color', - 'background-color', 'text-align', 'margin', 'padding' - ]; - let styleStr = ''; - essentialStyles.forEach(prop => { - const value = computed.getPropertyValue(prop); - if (value) { - styleStr += `${prop}: ${value}; `; - } - }); - if (styleStr) { - el.setAttribute('style', styleStr); - } - }); - const html = ` @@ -99,6 +80,8 @@ function captureSelection() {
${container.innerHTML} +`; + `; return {