From 3375fd4b63b11de9653c60354214d3352987f314 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 Sep 2025 22:37:51 -0700 Subject: [PATCH 01/24] We don't need to call tailwind-merge independently anymore. --- browser-extension/tests/playground/claude.tsx | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/browser-extension/tests/playground/claude.tsx b/browser-extension/tests/playground/claude.tsx index 8e8a15b..cabd026 100644 --- a/browser-extension/tests/playground/claude.tsx +++ b/browser-extension/tests/playground/claude.tsx @@ -1,6 +1,5 @@ import { Eye, EyeOff, Search, Settings, Trash2 } from 'lucide-react' import { useMemo, useState } from 'react' -import { twMerge } from 'tailwind-merge' import Badge from '@/components/Badge' import { badgeCVA } from '@/components/design' import MultiSegment from '@/components/MultiSegment' @@ -157,13 +156,11 @@ export const ClaudePrototype = () => { From 4e239637d4fe5e5a00c93d5ea5f11b06917eae98 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 08:14:53 -0700 Subject: [PATCH 02/24] Prepare to show commentSpot on page. --- browser-extension/tests/har-view.ts | 67 ++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 88d3dd8..524ddb3 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -332,10 +332,25 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.log('Fetched content script, patching webextension-polyfill...'); // Replace the problematic webextension-polyfill error check - const patchedCode = code.replace( + let patchedCode = code.replace( /throw new Error\\("This script should only be loaded in a browser extension\\."/g, 'console.warn("Webextension-polyfill check bypassed for HAR testing"' ); + + // Patch the content script to track CommentSpots globally + patchedCode = patchedCode.replace( + /sendEventToBackground\\('ENHANCED', spot\\)/g, + \`sendEventToBackground('ENHANCED', spot); + window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; + window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'ENHANCED'});\` + ); + + patchedCode = patchedCode.replace( + /sendEventToBackground\\('DESTROYED', spot\\)/g, + \`sendEventToBackground('DESTROYED', spot); + window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; + window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'DESTROYED'});\` + ); // Mock necessary APIs before executing window.chrome = window.chrome || { @@ -347,6 +362,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } }; window.browser = window.chrome; + + // Create a global registry to track comment spots for debugging + window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; // Execute the patched script const script = document.createElement('script'); @@ -442,6 +460,53 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { }); document.body.appendChild(rebuildButton); + + // Create CommentSpot display + const commentSpotDisplay = document.createElement('div'); + commentSpotDisplay.id = 'gitcasso-comment-spots'; + commentSpotDisplay.style.cssText = \` + position: fixed; + top: 80px; + right: 20px; + width: 300px; + max-height: 400px; + background: rgba(255, 255, 255, 0.95); + border: 1px solid #ddd; + border-radius: 8px; + padding: 15px; + font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; + font-size: 11px; + line-height: 1.4; + overflow-y: auto; + z-index: 999998; + box-shadow: 0 4px 12px rgba(0,0,0,0.2); + backdrop-filter: blur(10px); + \`; + + // Function to update CommentSpot display + function updateCommentSpotDisplay() { + const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : []; + + const content = spots.length > 0 + ? \`
CommentSpots (\${spots.length}):
\${JSON.stringify(spots, null, 2)}
\` + : '
No CommentSpots detected yet...
'; + + commentSpotDisplay.innerHTML = content; + } + + // Initial update + updateCommentSpotDisplay(); + + // Update display periodically + setInterval(updateCommentSpotDisplay, 2000); + + document.body.appendChild(commentSpotDisplay); + + // Expose textarea registry access function globally + window.gitcassoGetCommentSpots = function() { + // Return the global comment spots array + return window.gitcassoCommentSpots || []; + }; ` if (!html.includes('')) { From cda66526fd752a22259074206f74d182ada944d7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 08:39:21 -0700 Subject: [PATCH 03/24] The comment spots are found! --- browser-extension/tests/har-view.ts | 91 ++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 524ddb3..167d2b7 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -338,38 +338,82 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { ); // Patch the content script to track CommentSpots globally - patchedCode = patchedCode.replace( - /sendEventToBackground\\('ENHANCED', spot\\)/g, - \`sendEventToBackground('ENHANCED', spot); - window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'ENHANCED'});\` - ); - - patchedCode = patchedCode.replace( - /sendEventToBackground\\('DESTROYED', spot\\)/g, - \`sendEventToBackground('DESTROYED', spot); - window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'DESTROYED'});\` - ); + console.log('Original code length:', code.length); + console.log('Code sample around sendEventToBackground:', + code.match(/sendEventToBackground[^;}]{0,100}/g) || 'No matches found'); + + // More flexible regex to match both quote styles and variations + const enhancedMatches = patchedCode.match(/sendEventToBackground\\(['"](ENHANCED)['"], ?spot\\)/g); + const destroyedMatches = patchedCode.match(/sendEventToBackground\\(['"](DESTROYED)['"], ?spot\\)/g); + console.log('ENHANCED matches found:', enhancedMatches?.length || 0); + console.log('DESTROYED matches found:', destroyedMatches?.length || 0); + + // Remove complex function patching - we'll use sendMessage interception instead + console.log('Skipping function patching, using sendMessage interception for CommentSpot tracking'); + + // Verify patches were applied + const functionPatchMatches = patchedCode.match(/window\\.gitcassoCommentSpots.*action: type/g); + console.log('Function patches applied:', functionPatchMatches?.length || 0); + if (functionPatchMatches && functionPatchMatches.length > 0) { + console.log('sendEventToBackground function successfully patched for CommentSpot tracking'); + } else { + console.warn('Failed to patch sendEventToBackground function'); + } // Mock necessary APIs before executing window.chrome = window.chrome || { runtime: { getURL: (path) => 'chrome-extension://gitcasso-test/' + path, onMessage: { addListener: () => {} }, - sendMessage: () => Promise.resolve(), + sendMessage: (message) => { + console.log('Mock sendMessage called with:', message); + return Promise.resolve(); + }, + id: 'gitcasso-test' + } + }; + window.browser = window.browser || { + runtime: { + getURL: (path) => 'chrome-extension://gitcasso-test/' + path, + onMessage: { addListener: () => {} }, + sendMessage: (message) => { + console.log('Mock browser.runtime.sendMessage called with:', message); + + // Track CommentSpots when they're sent via sendMessage + if (message && message.spot && message.type) { + try { + window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; + const trackingData = Object.assign({}, message.spot, { + timestamp: Date.now(), + action: message.type + }); + window.gitcassoCommentSpots.push(trackingData); + console.log('CommentSpot captured via sendMessage:', trackingData); + console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length); + } catch (e) { + console.error('Failed to track CommentSpot via sendMessage:', e); + } + } + + return Promise.resolve(); + }, id: 'gitcasso-test' } }; - window.browser = window.chrome; // Create a global registry to track comment spots for debugging window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - // Execute the patched script - const script = document.createElement('script'); - script.textContent = patchedCode; - document.head.appendChild(script); + // Execute the patched script with error handling + try { + const script = document.createElement('script'); + script.textContent = patchedCode; + document.head.appendChild(script); + console.log('Content script executed successfully'); + } catch (error) { + console.error('Failed to execute patched content script:', error); + console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000)); + } console.log('Gitcasso content script loaded with location patching for:', '${urlParts.href}'); }) @@ -487,9 +531,16 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { function updateCommentSpotDisplay() { const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : []; + // Debug logging + if (window.gitcassoCommentSpots) { + console.log('Raw gitcassoCommentSpots array:', window.gitcassoCommentSpots); + } + console.log('Spots for display:', spots); + console.log('All textareas on page:', document.querySelectorAll('textarea').length); + const content = spots.length > 0 ? \`
CommentSpots (\${spots.length}):
\${JSON.stringify(spots, null, 2)}
\` - : '
No CommentSpots detected yet...
'; + : '
No CommentSpots detected yet...
Textareas found: ' + document.querySelectorAll('textarea').length + '
'; commentSpotDisplay.innerHTML = content; } From 219bb104832ca45f2d0c9e5a9bc58a257f4923cb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 09:22:15 -0700 Subject: [PATCH 04/24] Progress. --- browser-extension/src/entrypoints/content.ts | 7 +- browser-extension/src/lib/registries.ts | 6 +- browser-extension/tests/har-view.ts | 78 +++++++++++++++++++- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 2093239..df477fd 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -6,7 +6,10 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' const enhancers = new EnhancerRegistry() const enhancedTextareas = new TextareaRegistry() -function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { +// Expose for debugging in har:view +;(window as any).gitcassoTextareaRegistry = enhancedTextareas + +function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot, textarea?: HTMLTextAreaElement): void { const message: CommentEvent = { spot, type, @@ -17,7 +20,7 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot } enhancedTextareas.setEventHandlers( - (spot) => sendEventToBackground('ENHANCED', spot), + (spot, textarea) => sendEventToBackground('ENHANCED', spot, textarea), (spot) => sendEventToBackground('DESTROYED', spot), ) diff --git a/browser-extension/src/lib/registries.ts b/browser-extension/src/lib/registries.ts index 3482dcc..5bcee1a 100644 --- a/browser-extension/src/lib/registries.ts +++ b/browser-extension/src/lib/registries.ts @@ -105,11 +105,11 @@ export class EnhancerRegistry { export class TextareaRegistry { private textareas = new Map() - private onEnhanced?: (spot: CommentSpot) => void + private onEnhanced?: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void private onDestroyed?: (spot: CommentSpot) => void setEventHandlers( - onEnhanced: (spot: CommentSpot) => void, + onEnhanced: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void, onDestroyed: (spot: CommentSpot) => void, ): void { this.onEnhanced = onEnhanced @@ -118,7 +118,7 @@ export class TextareaRegistry { register(textareaInfo: EnhancedTextarea): void { this.textareas.set(textareaInfo.textarea, textareaInfo) - this.onEnhanced?.(textareaInfo.spot) + this.onEnhanced?.(textareaInfo.spot, textareaInfo.textarea) } unregisterDueToModification(textarea: HTMLTextAreaElement): void { diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 167d2b7..9a2d432 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -403,13 +403,61 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { // Create a global registry to track comment spots for debugging window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - + + // Helper function to extract textarea info for debugging + function getTextareaInfo(textarea) { + const rect = textarea.getBoundingClientRect(); + return { + id: textarea.id || '', + name: textarea.name || '', + className: textarea.className || '', + tagName: textarea.tagName, + placeholder: textarea.placeholder || '', + value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', + parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', + position: { + top: rect.top, + left: rect.left, + width: rect.width, + height: rect.height + } + }; + } + // Execute the patched script with error handling try { const script = document.createElement('script'); script.textContent = patchedCode; document.head.appendChild(script); console.log('Content script executed successfully'); + + // After the script loads, patch the TextareaRegistry if available + setTimeout(() => { + if (window.gitcassoTextareaRegistry) { + const originalSetEventHandlers = window.gitcassoTextareaRegistry.setEventHandlers; + window.gitcassoTextareaRegistry.setEventHandlers = function(onEnhanced, onDestroyed) { + console.log('Patching TextareaRegistry.setEventHandlers'); + const wrappedOnEnhanced = function(spot, textarea) { + console.log('onEnhanced called with spot and textarea:', spot, textarea); + const textareaInfo = getTextareaInfo(textarea); + console.log('Textarea details:', textareaInfo); + + // Store enhanced info with textarea details + window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; + const trackingData = Object.assign({}, spot, { + timestamp: Date.now(), + action: 'ENHANCED', + textareaInfo: textareaInfo + }); + window.gitcassoCommentSpots.push(trackingData); + + return onEnhanced(spot, textarea); + }; + return originalSetEventHandlers.call(this, wrappedOnEnhanced, onDestroyed); + }; + } + }, 100); + } catch (error) { console.error('Failed to execute patched content script:', error); console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000)); @@ -538,9 +586,31 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.log('Spots for display:', spots); console.log('All textareas on page:', document.querySelectorAll('textarea').length); - const content = spots.length > 0 - ? \`
CommentSpots (\${spots.length}):
\${JSON.stringify(spots, null, 2)}
\` - : '
No CommentSpots detected yet...
Textareas found: ' + document.querySelectorAll('textarea').length + '
'; + let content = ''; + if (spots.length > 0) { + content = \`
CommentSpots (\${spots.length}):
\`; + + spots.forEach((spot, index) => { + const hasTextareaInfo = spot.textareaInfo; + const spotData = Object.assign({}, spot); + delete spotData.textareaInfo; // Remove from main display + + content += \`
\`; + content += \`
Spot \${index + 1}:
\`; + content += \`
\${JSON.stringify(spotData, null, 2)}
\`; + + if (hasTextareaInfo) { + content += \`
Textarea Info:
\`; + content += \`
\${JSON.stringify(spot.textareaInfo, null, 2)}
\`; + } else { + content += \`
No textarea info captured
\`; + } + + content += \`
\`; + }); + } else { + content = '
No CommentSpots detected yet...
Textareas found: ' + document.querySelectorAll('textarea').length + '
'; + } commentSpotDisplay.innerHTML = content; } From c8b6e8a3279fa85142a62a05cfb8e332307811d3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 09:26:09 -0700 Subject: [PATCH 05/24] More progress. --- browser-extension/src/entrypoints/content.ts | 21 +++++++ browser-extension/tests/har-view.ts | 58 ++++---------------- 2 files changed, 31 insertions(+), 48 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index df477fd..190072b 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -14,6 +14,27 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot spot, type, } + + // Add textarea debugging info for har:view testing + if (textarea && (window as any).gitcassoDebugMode) { + const rect = textarea.getBoundingClientRect(); + (message as any).textareaInfo = { + id: textarea.id || '', + name: textarea.name || '', + className: textarea.className || '', + tagName: textarea.tagName, + placeholder: textarea.placeholder || '', + value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', + parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', + position: { + top: rect.top, + left: rect.left, + width: rect.width, + height: rect.height + } + }; + } + browser.runtime.sendMessage(message).catch((error) => { logger.debug('Failed to send event to background:', error) }) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 9a2d432..65ff999 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -360,6 +360,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.warn('Failed to patch sendEventToBackground function'); } + // Enable debug mode for textarea info capture + window.gitcassoDebugMode = true; + // Mock necessary APIs before executing window.chrome = window.chrome || { runtime: { @@ -387,6 +390,13 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { timestamp: Date.now(), action: message.type }); + + // Include textarea info if available in the message + if (message.textareaInfo) { + trackingData.textareaInfo = message.textareaInfo; + console.log('Textarea info captured:', message.textareaInfo); + } + window.gitcassoCommentSpots.push(trackingData); console.log('CommentSpot captured via sendMessage:', trackingData); console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length); @@ -404,60 +414,12 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { // Create a global registry to track comment spots for debugging window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - // Helper function to extract textarea info for debugging - function getTextareaInfo(textarea) { - const rect = textarea.getBoundingClientRect(); - return { - id: textarea.id || '', - name: textarea.name || '', - className: textarea.className || '', - tagName: textarea.tagName, - placeholder: textarea.placeholder || '', - value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', - parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', - position: { - top: rect.top, - left: rect.left, - width: rect.width, - height: rect.height - } - }; - } - // Execute the patched script with error handling try { const script = document.createElement('script'); script.textContent = patchedCode; document.head.appendChild(script); console.log('Content script executed successfully'); - - // After the script loads, patch the TextareaRegistry if available - setTimeout(() => { - if (window.gitcassoTextareaRegistry) { - const originalSetEventHandlers = window.gitcassoTextareaRegistry.setEventHandlers; - window.gitcassoTextareaRegistry.setEventHandlers = function(onEnhanced, onDestroyed) { - console.log('Patching TextareaRegistry.setEventHandlers'); - const wrappedOnEnhanced = function(spot, textarea) { - console.log('onEnhanced called with spot and textarea:', spot, textarea); - const textareaInfo = getTextareaInfo(textarea); - console.log('Textarea details:', textareaInfo); - - // Store enhanced info with textarea details - window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - const trackingData = Object.assign({}, spot, { - timestamp: Date.now(), - action: 'ENHANCED', - textareaInfo: textareaInfo - }); - window.gitcassoCommentSpots.push(trackingData); - - return onEnhanced(spot, textarea); - }; - return originalSetEventHandlers.call(this, wrappedOnEnhanced, onDestroyed); - }; - } - }, 100); - } catch (error) { console.error('Failed to execute patched content script:', error); console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000)); From 11a98975b9a8e3070456a76d9c317f28f4c88f0f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 09:33:56 -0700 Subject: [PATCH 06/24] Simplify. --- browser-extension/src/entrypoints/content.ts | 20 ---- browser-extension/tests/har-view.ts | 101 ++++++++++++------- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 190072b..0984f79 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -15,26 +15,6 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot type, } - // Add textarea debugging info for har:view testing - if (textarea && (window as any).gitcassoDebugMode) { - const rect = textarea.getBoundingClientRect(); - (message as any).textareaInfo = { - id: textarea.id || '', - name: textarea.name || '', - className: textarea.className || '', - tagName: textarea.tagName, - placeholder: textarea.placeholder || '', - value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', - parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', - position: { - top: rect.top, - left: rect.left, - width: rect.width, - height: rect.height - } - }; - } - browser.runtime.sendMessage(message).catch((error) => { logger.debug('Failed to send event to background:', error) }) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 65ff999..e8e5777 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -360,8 +360,6 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.warn('Failed to patch sendEventToBackground function'); } - // Enable debug mode for textarea info capture - window.gitcassoDebugMode = true; // Mock necessary APIs before executing window.chrome = window.chrome || { @@ -386,17 +384,41 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { if (message && message.spot && message.type) { try { window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; + + // Capture textarea debugging info here instead of in production code + let textareaInfo = null; + if (message.type === 'ENHANCED' && window.gitcassoTextareaRegistry) { + const textareas = document.querySelectorAll('textarea'); + for (const textarea of textareas) { + const enhanced = window.gitcassoTextareaRegistry.get(textarea); + if (enhanced && enhanced.spot.unique_key === message.spot.unique_key) { + const rect = textarea.getBoundingClientRect(); + textareaInfo = { + id: textarea.id || '', + name: textarea.name || '', + className: textarea.className || '', + tagName: textarea.tagName, + placeholder: textarea.placeholder || '', + value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', + parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', + position: { + top: rect.top, + left: rect.left, + width: rect.width, + height: rect.height + } + }; + break; + } + } + } + const trackingData = Object.assign({}, message.spot, { timestamp: Date.now(), - action: message.type + action: message.type, + textareaInfo }); - // Include textarea info if available in the message - if (message.textareaInfo) { - trackingData.textareaInfo = message.textareaInfo; - console.log('Textarea info captured:', message.textareaInfo); - } - window.gitcassoCommentSpots.push(trackingData); console.log('CommentSpot captured via sendMessage:', trackingData); console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length); @@ -537,42 +559,43 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { backdrop-filter: blur(10px); \`; - // Function to update CommentSpot display + // Simplified display formatting + const styles = { + header: 'font-weight: bold; margin-bottom: 8px; color: #333;', + spotContainer: 'margin-bottom: 12px; padding: 8px; border: 1px solid #eee; border-radius: 4px;', + spotTitle: 'font-weight: bold; color: #555;', + jsonPre: 'margin: 4px 0; font-size: 10px;', + textareaHeader: 'font-weight: bold; color: #007acc; margin-top: 8px;', + textareaPre: 'margin: 4px 0; font-size: 10px; color: #666;', + noInfo: 'color: #999; font-style: italic; margin-top: 4px;', + empty: 'color: #666; font-style: italic;' + }; + + function formatSpot(spot, index) { + const { textareaInfo, ...spotData } = spot; + return \` +
+
Spot \${index + 1}:
+
\${JSON.stringify(spotData, null, 2)}
+ \${textareaInfo + ? \`
Textarea Info:
+
\${JSON.stringify(textareaInfo, null, 2)}
\` + : \`
No textarea info captured
\` + } +
+ \`; + } + function updateCommentSpotDisplay() { const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : []; - // Debug logging - if (window.gitcassoCommentSpots) { - console.log('Raw gitcassoCommentSpots array:', window.gitcassoCommentSpots); - } console.log('Spots for display:', spots); console.log('All textareas on page:', document.querySelectorAll('textarea').length); - let content = ''; - if (spots.length > 0) { - content = \`
CommentSpots (\${spots.length}):
\`; - - spots.forEach((spot, index) => { - const hasTextareaInfo = spot.textareaInfo; - const spotData = Object.assign({}, spot); - delete spotData.textareaInfo; // Remove from main display - - content += \`
\`; - content += \`
Spot \${index + 1}:
\`; - content += \`
\${JSON.stringify(spotData, null, 2)}
\`; - - if (hasTextareaInfo) { - content += \`
Textarea Info:
\`; - content += \`
\${JSON.stringify(spot.textareaInfo, null, 2)}
\`; - } else { - content += \`
No textarea info captured
\`; - } - - content += \`
\`; - }); - } else { - content = '
No CommentSpots detected yet...
Textareas found: ' + document.querySelectorAll('textarea').length + '
'; - } + const content = spots.length > 0 + ? \`
CommentSpots (\${spots.length}):
+ \${spots.map(formatSpot).join('')}\` + : \`
No CommentSpots detected yet...
Textareas found: \${document.querySelectorAll('textarea').length}
\`; commentSpotDisplay.innerHTML = content; } From 8056bc7ca2a1b993028b82b43728acb277676a4f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 09:47:15 -0700 Subject: [PATCH 07/24] Progress. --- browser-extension/src/lib/registries.ts | 4 + browser-extension/tests/har-view.ts | 154 ++++++------------------ 2 files changed, 39 insertions(+), 119 deletions(-) diff --git a/browser-extension/src/lib/registries.ts b/browser-extension/src/lib/registries.ts index 5bcee1a..e9678fb 100644 --- a/browser-extension/src/lib/registries.ts +++ b/browser-extension/src/lib/registries.ts @@ -132,4 +132,8 @@ export class TextareaRegistry { get(textarea: HTMLTextAreaElement): EnhancedTextarea | undefined { return this.textareas.get(textarea) } + + getAllEnhanced(): EnhancedTextarea[] { + return Array.from(this.textareas.values()) + } } diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index e8e5777..98d3c44 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -337,115 +337,23 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { 'console.warn("Webextension-polyfill check bypassed for HAR testing"' ); - // Patch the content script to track CommentSpots globally - console.log('Original code length:', code.length); - console.log('Code sample around sendEventToBackground:', - code.match(/sendEventToBackground[^;}]{0,100}/g) || 'No matches found'); - - // More flexible regex to match both quote styles and variations - const enhancedMatches = patchedCode.match(/sendEventToBackground\\(['"](ENHANCED)['"], ?spot\\)/g); - const destroyedMatches = patchedCode.match(/sendEventToBackground\\(['"](DESTROYED)['"], ?spot\\)/g); - console.log('ENHANCED matches found:', enhancedMatches?.length || 0); - console.log('DESTROYED matches found:', destroyedMatches?.length || 0); - - // Remove complex function patching - we'll use sendMessage interception instead - console.log('Skipping function patching, using sendMessage interception for CommentSpot tracking'); - - // Verify patches were applied - const functionPatchMatches = patchedCode.match(/window\\.gitcassoCommentSpots.*action: type/g); - console.log('Function patches applied:', functionPatchMatches?.length || 0); - if (functionPatchMatches && functionPatchMatches.length > 0) { - console.log('sendEventToBackground function successfully patched for CommentSpot tracking'); - } else { - console.warn('Failed to patch sendEventToBackground function'); - } - - // Mock necessary APIs before executing window.chrome = window.chrome || { runtime: { getURL: (path) => 'chrome-extension://gitcasso-test/' + path, onMessage: { addListener: () => {} }, - sendMessage: (message) => { - console.log('Mock sendMessage called with:', message); - return Promise.resolve(); - }, - id: 'gitcasso-test' - } - }; - window.browser = window.browser || { - runtime: { - getURL: (path) => 'chrome-extension://gitcasso-test/' + path, - onMessage: { addListener: () => {} }, - sendMessage: (message) => { - console.log('Mock browser.runtime.sendMessage called with:', message); - - // Track CommentSpots when they're sent via sendMessage - if (message && message.spot && message.type) { - try { - window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - - // Capture textarea debugging info here instead of in production code - let textareaInfo = null; - if (message.type === 'ENHANCED' && window.gitcassoTextareaRegistry) { - const textareas = document.querySelectorAll('textarea'); - for (const textarea of textareas) { - const enhanced = window.gitcassoTextareaRegistry.get(textarea); - if (enhanced && enhanced.spot.unique_key === message.spot.unique_key) { - const rect = textarea.getBoundingClientRect(); - textareaInfo = { - id: textarea.id || '', - name: textarea.name || '', - className: textarea.className || '', - tagName: textarea.tagName, - placeholder: textarea.placeholder || '', - value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', - parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', - position: { - top: rect.top, - left: rect.left, - width: rect.width, - height: rect.height - } - }; - break; - } - } - } - - const trackingData = Object.assign({}, message.spot, { - timestamp: Date.now(), - action: message.type, - textareaInfo - }); - - window.gitcassoCommentSpots.push(trackingData); - console.log('CommentSpot captured via sendMessage:', trackingData); - console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length); - } catch (e) { - console.error('Failed to track CommentSpot via sendMessage:', e); - } - } - - return Promise.resolve(); - }, + sendMessage: () => Promise.resolve(), id: 'gitcasso-test' } }; + window.browser = window.chrome; + + + // Execute the patched script + const script = document.createElement('script'); + script.textContent = patchedCode; + document.head.appendChild(script); - // Create a global registry to track comment spots for debugging - window.gitcassoCommentSpots = window.gitcassoCommentSpots || []; - - // Execute the patched script with error handling - try { - const script = document.createElement('script'); - script.textContent = patchedCode; - document.head.appendChild(script); - console.log('Content script executed successfully'); - } catch (error) { - console.error('Failed to execute patched content script:', error); - console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000)); - } console.log('Gitcasso content script loaded with location patching for:', '${urlParts.href}'); }) @@ -571,30 +479,44 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { empty: 'color: #666; font-style: italic;' }; - function formatSpot(spot, index) { - const { textareaInfo, ...spotData } = spot; + function formatSpot(enhanced, index) { + const { textarea, spot } = enhanced; + const rect = textarea.getBoundingClientRect(); + const textareaInfo = { + id: textarea.id || '', + name: textarea.name || '', + className: textarea.className || '', + tagName: textarea.tagName, + placeholder: textarea.placeholder || '', + value: textarea.value ? textarea.value.substring(0, 50) + '...' : '', + parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '', + position: { + top: rect.top, + left: rect.left, + width: rect.width, + height: rect.height + } + }; + return \`
Spot \${index + 1}:
-
\${JSON.stringify(spotData, null, 2)}
- \${textareaInfo - ? \`
Textarea Info:
-
\${JSON.stringify(textareaInfo, null, 2)}
\` - : \`
No textarea info captured
\` - } +
\${JSON.stringify(spot, null, 2)}
+
Textarea Info:
+
\${JSON.stringify(textareaInfo, null, 2)}
\`; } function updateCommentSpotDisplay() { - const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : []; + const enhanced = window.enhancedTextareas ? window.enhancedTextareas.getAllEnhanced() : []; - console.log('Spots for display:', spots); + console.log('Enhanced textareas:', enhanced.length); console.log('All textareas on page:', document.querySelectorAll('textarea').length); - const content = spots.length > 0 - ? \`
CommentSpots (\${spots.length}):
- \${spots.map(formatSpot).join('')}\` + const content = enhanced.length > 0 + ? \`
CommentSpots (\${enhanced.length}):
+ \${enhanced.map(formatSpot).join('')}\` : \`
No CommentSpots detected yet...
Textareas found: \${document.querySelectorAll('textarea').length}
\`; commentSpotDisplay.innerHTML = content; @@ -607,12 +529,6 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { setInterval(updateCommentSpotDisplay, 2000); document.body.appendChild(commentSpotDisplay); - - // Expose textarea registry access function globally - window.gitcassoGetCommentSpots = function() { - // Return the global comment spots array - return window.gitcassoCommentSpots || []; - }; ` if (!html.includes('')) { From 518965c9f665565172783fbe7585b637bf95baae Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 09:52:52 -0700 Subject: [PATCH 08/24] Progress. --- browser-extension/tests/har-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 98d3c44..3b3e2e0 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -509,7 +509,7 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } function updateCommentSpotDisplay() { - const enhanced = window.enhancedTextareas ? window.enhancedTextareas.getAllEnhanced() : []; + const enhanced = window.gitcassoTextareaRegistry ? window.gitcassoTextareaRegistry.getAllEnhanced() : []; console.log('Enhanced textareas:', enhanced.length); console.log('All textareas on page:', document.querySelectorAll('textarea').length); From 10eff915e0065d2b2685c78f4954b0b84a11f6b0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:01:59 -0700 Subject: [PATCH 09/24] Format. --- browser-extension/src/entrypoints/content.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 0984f79..ae9790a 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -9,7 +9,11 @@ const enhancedTextareas = new TextareaRegistry() // Expose for debugging in har:view ;(window as any).gitcassoTextareaRegistry = enhancedTextareas -function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot, textarea?: HTMLTextAreaElement): void { +function sendEventToBackground( + type: 'ENHANCED' | 'DESTROYED', + spot: CommentSpot, + textarea?: HTMLTextAreaElement, +): void { const message: CommentEvent = { spot, type, From 97c8f15476782dfd0d10d5e2991be7b6cf77c114 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:16:47 -0700 Subject: [PATCH 10/24] Minimize diff. --- browser-extension/src/entrypoints/content.ts | 8 ++------ browser-extension/src/lib/registries.ts | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index ae9790a..52bd92c 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -9,11 +9,7 @@ const enhancedTextareas = new TextareaRegistry() // Expose for debugging in har:view ;(window as any).gitcassoTextareaRegistry = enhancedTextareas -function sendEventToBackground( - type: 'ENHANCED' | 'DESTROYED', - spot: CommentSpot, - textarea?: HTMLTextAreaElement, -): void { +function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { const message: CommentEvent = { spot, type, @@ -25,7 +21,7 @@ function sendEventToBackground( } enhancedTextareas.setEventHandlers( - (spot, textarea) => sendEventToBackground('ENHANCED', spot, textarea), + (spot) => sendEventToBackground('ENHANCED', spot), (spot) => sendEventToBackground('DESTROYED', spot), ) diff --git a/browser-extension/src/lib/registries.ts b/browser-extension/src/lib/registries.ts index e9678fb..2c7cc07 100644 --- a/browser-extension/src/lib/registries.ts +++ b/browser-extension/src/lib/registries.ts @@ -105,11 +105,11 @@ export class EnhancerRegistry { export class TextareaRegistry { private textareas = new Map() - private onEnhanced?: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void + private onEnhanced?: (spot: CommentSpot) => void private onDestroyed?: (spot: CommentSpot) => void setEventHandlers( - onEnhanced: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void, + onEnhanced: (spot: CommentSpot) => void, onDestroyed: (spot: CommentSpot) => void, ): void { this.onEnhanced = onEnhanced @@ -118,7 +118,7 @@ export class TextareaRegistry { register(textareaInfo: EnhancedTextarea): void { this.textareas.set(textareaInfo.textarea, textareaInfo) - this.onEnhanced?.(textareaInfo.spot, textareaInfo.textarea) + this.onEnhanced?.(textareaInfo.spot) } unregisterDueToModification(textarea: HTMLTextAreaElement): void { From 91a8c1339d73c3df66f4effcce35a7d25257552c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:17:02 -0700 Subject: [PATCH 11/24] Add a slash command for finishing changes in the current working directory. --- .claude/commands/finish-wc.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .claude/commands/finish-wc.md diff --git a/.claude/commands/finish-wc.md b/.claude/commands/finish-wc.md new file mode 100644 index 0000000..b8021a7 --- /dev/null +++ b/.claude/commands/finish-wc.md @@ -0,0 +1 @@ +Run `git status` to see the changes in the working copy. Complete whatever tasks are necessary to complete this change. Make sure that `pnpm -r precommit` succeeds. Don't fix `precommit` just be reverting the changes, the goal is to complete the change. \ No newline at end of file From 66a6a850bc823cc1f260a4b77724ef964aeca41f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:18:40 -0700 Subject: [PATCH 12/24] More diff minimization. --- browser-extension/src/entrypoints/content.ts | 5 ++--- browser-extension/tests/har-view.ts | 7 +------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 52bd92c..b873383 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -6,15 +6,14 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' const enhancers = new EnhancerRegistry() const enhancedTextareas = new TextareaRegistry() -// Expose for debugging in har:view -;(window as any).gitcassoTextareaRegistry = enhancedTextareas + // Expose for debugging in har:view + ; (window as any).gitcassoTextareaRegistry = enhancedTextareas function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { const message: CommentEvent = { spot, type, } - browser.runtime.sendMessage(message).catch((error) => { logger.debug('Failed to send event to background:', error) }) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 3b3e2e0..c1f060c 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -332,11 +332,10 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.log('Fetched content script, patching webextension-polyfill...'); // Replace the problematic webextension-polyfill error check - let patchedCode = code.replace( + const patchedCode = code.replace( /throw new Error\\("This script should only be loaded in a browser extension\\."/g, 'console.warn("Webextension-polyfill check bypassed for HAR testing"' ); - // Mock necessary APIs before executing window.chrome = window.chrome || { runtime: { @@ -347,14 +346,10 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } }; window.browser = window.chrome; - - // Execute the patched script const script = document.createElement('script'); script.textContent = patchedCode; document.head.appendChild(script); - - console.log('Gitcasso content script loaded with location patching for:', '${urlParts.href}'); }) .catch(error => { From 0c7677fa47ed61bfecd0bf85588d3601f11e8705 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:21:30 -0700 Subject: [PATCH 13/24] Make the first update more effective. --- browser-extension/tests/har-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index c1f060c..9df3786 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -518,7 +518,7 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } // Initial update - updateCommentSpotDisplay(); + setTimeout(updateCommentSpotDisplay, 100); // Update display periodically setInterval(updateCommentSpotDisplay, 2000); From dd4e5dc7222207593ea584a236f33cc9e949e073 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 10:38:42 -0700 Subject: [PATCH 14/24] fixup. --- browser-extension/src/entrypoints/content.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index b873383..7f901c3 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -6,8 +6,8 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' const enhancers = new EnhancerRegistry() const enhancedTextareas = new TextareaRegistry() - // Expose for debugging in har:view - ; (window as any).gitcassoTextareaRegistry = enhancedTextareas +// Expose for debugging in har:view +;(window as any).gitcassoTextareaRegistry = enhancedTextareas function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { const message: CommentEvent = { From 87b4f8eed2fb868453b0b8953f71ec3a52117bc6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 11:42:06 -0700 Subject: [PATCH 15/24] Some progress. --- browser-extension/tests/har-view.ts | 65 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 9df3786..7a68053 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -316,7 +316,7 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.log('Patching window.location to simulate original URL...'); // Use history.pushState to change the pathname - window.history.pushState({}, '', '${urlParts.pathname}'); + window.history.pushState({}, '', '` + urlParts.pathname + `'); console.log('Location patched:', { hostname: window.location.hostname, @@ -333,9 +333,10 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { // Replace the problematic webextension-polyfill error check const patchedCode = code.replace( - /throw new Error\\("This script should only be loaded in a browser extension\\."/g, - 'console.warn("Webextension-polyfill check bypassed for HAR testing"' + 'throw new Error("This script should only be loaded in a browser extension.")', + 'console.warn("Webextension-polyfill check bypassed for HAR testing")' ); + // Mock necessary APIs before executing window.chrome = window.chrome || { runtime: { @@ -346,11 +347,12 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } }; window.browser = window.chrome; + // Execute the patched script const script = document.createElement('script'); script.textContent = patchedCode; document.head.appendChild(script); - console.log('Gitcasso content script loaded with location patching for:', '${urlParts.href}'); + console.log('Gitcasso content script loaded with location patching for:', '` + urlParts.href + `'); }) .catch(error => { console.error('Failed to load and patch content script:', error); @@ -443,24 +445,23 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { // Create CommentSpot display const commentSpotDisplay = document.createElement('div'); commentSpotDisplay.id = 'gitcasso-comment-spots'; - commentSpotDisplay.style.cssText = \` - position: fixed; - top: 80px; - right: 20px; - width: 300px; - max-height: 400px; - background: rgba(255, 255, 255, 0.95); - border: 1px solid #ddd; - border-radius: 8px; - padding: 15px; - font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; - font-size: 11px; - line-height: 1.4; - overflow-y: auto; - z-index: 999998; - box-shadow: 0 4px 12px rgba(0,0,0,0.2); - backdrop-filter: blur(10px); - \`; + commentSpotDisplay.style.cssText = + 'position: fixed;' + + 'top: 80px;' + + 'right: 20px;' + + 'width: 300px;' + + 'max-height: 400px;' + + 'background: rgba(255, 255, 255, 0.95);' + + 'border: 1px solid #ddd;' + + 'border-radius: 8px;' + + 'padding: 15px;' + + 'font-family: Monaco, Menlo, Ubuntu Mono, monospace;' + + 'font-size: 11px;' + + 'line-height: 1.4;' + + 'overflow-y: auto;' + + 'z-index: 999998;' + + 'box-shadow: 0 4px 12px rgba(0,0,0,0.2);' + + 'backdrop-filter: blur(10px);'; // Simplified display formatting const styles = { @@ -493,14 +494,12 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { } }; - return \` -
-
Spot \${index + 1}:
-
\${JSON.stringify(spot, null, 2)}
-
Textarea Info:
-
\${JSON.stringify(textareaInfo, null, 2)}
-
- \`; + return '
' + + '
Spot ' + (index + 1) + ':
' + + '
' + JSON.stringify(spot, null, 2) + '
' + + '
Textarea Info:
' + + '
' + JSON.stringify(textareaInfo, null, 2) + '
' + + '
'; } function updateCommentSpotDisplay() { @@ -510,9 +509,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { console.log('All textareas on page:', document.querySelectorAll('textarea').length); const content = enhanced.length > 0 - ? \`
CommentSpots (\${enhanced.length}):
- \${enhanced.map(formatSpot).join('')}\` - : \`
No CommentSpots detected yet...
Textareas found: \${document.querySelectorAll('textarea').length}
\`; + ? '
CommentSpots (' + enhanced.length + '):
' + + enhanced.map(formatSpot).join('') + : '
No CommentSpots detected yet...
Textareas found: ' + document.querySelectorAll('textarea').length + '
'; commentSpotDisplay.innerHTML = content; } From c859f14c494f291e31404171508b00380f41b2bf Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 12:16:05 -0700 Subject: [PATCH 16/24] Fixed up! --- browser-extension/src/entrypoints/content.ts | 28 +++++++++++--------- browser-extension/tests/har-view.ts | 16 +++-------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 7f901c3..7e4907e 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -6,8 +6,8 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' const enhancers = new EnhancerRegistry() const enhancedTextareas = new TextareaRegistry() -// Expose for debugging in har:view -;(window as any).gitcassoTextareaRegistry = enhancedTextareas + // Expose for debugging in har:view + ; (window as any).gitcassoTextareaRegistry = enhancedTextareas function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { const message: CommentEvent = { @@ -88,16 +88,20 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) { logger.debug('activating textarea {}', textarea) injectStyles() - const enhancedTextarea = enhancers.tryToEnhance(textarea) - if (enhancedTextarea) { - logger.debug( - 'Identified textarea:', - enhancedTextarea.spot.type, - enhancedTextarea.spot.unique_key, - ) - enhancedTextareas.register(enhancedTextarea) - } else { - logger.debug('No handler found for textarea') + try { + const enhancedTextarea = enhancers.tryToEnhance(textarea) + if (enhancedTextarea) { + logger.debug( + 'Identified textarea:', + enhancedTextarea.spot.type, + enhancedTextarea.spot.unique_key, + ) + enhancedTextareas.register(enhancedTextarea) + } else { + logger.debug('No handler found for textarea') + } + } catch (e) { + logger.error(e) } } diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 7a68053..2441020 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -337,20 +337,10 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { 'console.warn("Webextension-polyfill check bypassed for HAR testing")' ); - // Mock necessary APIs before executing - window.chrome = window.chrome || { - runtime: { - getURL: (path) => 'chrome-extension://gitcasso-test/' + path, - onMessage: { addListener: () => {} }, - sendMessage: () => Promise.resolve(), - id: 'gitcasso-test' - } - }; - window.browser = window.chrome; - - // Execute the patched script + // Execute the patched script with browser API mocks prepended + const browserMocks = 'window.chrome=window.chrome||{runtime:{getURL:path=>"chrome-extension://gitcasso-test/"+path,onMessage:{addListener:()=>{}},sendMessage:()=>Promise.resolve(),id:"gitcasso-test"}};window.browser=window.chrome;'; const script = document.createElement('script'); - script.textContent = patchedCode; + script.textContent = browserMocks + patchedCode; document.head.appendChild(script); console.log('Gitcasso content script loaded with location patching for:', '` + urlParts.href + `'); }) From b981c292e35e46bf62ec579f4dcae7ccd0d8149b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 Sep 2025 12:16:49 -0700 Subject: [PATCH 17/24] Format fixup. --- browser-extension/src/entrypoints/content.ts | 4 ++-- browser-extension/tests/har-view.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/browser-extension/src/entrypoints/content.ts b/browser-extension/src/entrypoints/content.ts index 7e4907e..b49267f 100644 --- a/browser-extension/src/entrypoints/content.ts +++ b/browser-extension/src/entrypoints/content.ts @@ -6,8 +6,8 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' const enhancers = new EnhancerRegistry() const enhancedTextareas = new TextareaRegistry() - // Expose for debugging in har:view - ; (window as any).gitcassoTextareaRegistry = enhancedTextareas +// Expose for debugging in har:view +;(window as any).gitcassoTextareaRegistry = enhancedTextareas function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void { const message: CommentEvent = { diff --git a/browser-extension/tests/har-view.ts b/browser-extension/tests/har-view.ts index 2441020..69746e5 100644 --- a/browser-extension/tests/har-view.ts +++ b/browser-extension/tests/har-view.ts @@ -310,13 +310,16 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) { const urlParts = getUrlParts(key) // Inject patched content script with location patching - const contentScriptTag = ` + const contentScriptTag = + `