Skip to content

Commit 219bb10

Browse files
committed
Progress.
1 parent cda6652 commit 219bb10

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries'
66
const enhancers = new EnhancerRegistry()
77
const enhancedTextareas = new TextareaRegistry()
88

9-
function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void {
9+
// Expose for debugging in har:view
10+
;(window as any).gitcassoTextareaRegistry = enhancedTextareas
11+
12+
function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot, textarea?: HTMLTextAreaElement): void {
1013
const message: CommentEvent = {
1114
spot,
1215
type,
@@ -17,7 +20,7 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot
1720
}
1821

1922
enhancedTextareas.setEventHandlers(
20-
(spot) => sendEventToBackground('ENHANCED', spot),
23+
(spot, textarea) => sendEventToBackground('ENHANCED', spot, textarea),
2124
(spot) => sendEventToBackground('DESTROYED', spot),
2225
)
2326

browser-extension/src/lib/registries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ export class EnhancerRegistry {
105105

106106
export class TextareaRegistry {
107107
private textareas = new Map<HTMLTextAreaElement, EnhancedTextarea>()
108-
private onEnhanced?: (spot: CommentSpot) => void
108+
private onEnhanced?: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void
109109
private onDestroyed?: (spot: CommentSpot) => void
110110

111111
setEventHandlers(
112-
onEnhanced: (spot: CommentSpot) => void,
112+
onEnhanced: (spot: CommentSpot, textarea: HTMLTextAreaElement) => void,
113113
onDestroyed: (spot: CommentSpot) => void,
114114
): void {
115115
this.onEnhanced = onEnhanced
@@ -118,7 +118,7 @@ export class TextareaRegistry {
118118

119119
register<T extends CommentSpot>(textareaInfo: EnhancedTextarea<T>): void {
120120
this.textareas.set(textareaInfo.textarea, textareaInfo)
121-
this.onEnhanced?.(textareaInfo.spot)
121+
this.onEnhanced?.(textareaInfo.spot, textareaInfo.textarea)
122122
}
123123

124124
unregisterDueToModification(textarea: HTMLTextAreaElement): void {

browser-extension/tests/har-view.ts

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,61 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
403403
404404
// Create a global registry to track comment spots for debugging
405405
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
406-
406+
407+
// Helper function to extract textarea info for debugging
408+
function getTextareaInfo(textarea) {
409+
const rect = textarea.getBoundingClientRect();
410+
return {
411+
id: textarea.id || '',
412+
name: textarea.name || '',
413+
className: textarea.className || '',
414+
tagName: textarea.tagName,
415+
placeholder: textarea.placeholder || '',
416+
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
417+
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
418+
position: {
419+
top: rect.top,
420+
left: rect.left,
421+
width: rect.width,
422+
height: rect.height
423+
}
424+
};
425+
}
426+
407427
// Execute the patched script with error handling
408428
try {
409429
const script = document.createElement('script');
410430
script.textContent = patchedCode;
411431
document.head.appendChild(script);
412432
console.log('Content script executed successfully');
433+
434+
// After the script loads, patch the TextareaRegistry if available
435+
setTimeout(() => {
436+
if (window.gitcassoTextareaRegistry) {
437+
const originalSetEventHandlers = window.gitcassoTextareaRegistry.setEventHandlers;
438+
window.gitcassoTextareaRegistry.setEventHandlers = function(onEnhanced, onDestroyed) {
439+
console.log('Patching TextareaRegistry.setEventHandlers');
440+
const wrappedOnEnhanced = function(spot, textarea) {
441+
console.log('onEnhanced called with spot and textarea:', spot, textarea);
442+
const textareaInfo = getTextareaInfo(textarea);
443+
console.log('Textarea details:', textareaInfo);
444+
445+
// Store enhanced info with textarea details
446+
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
447+
const trackingData = Object.assign({}, spot, {
448+
timestamp: Date.now(),
449+
action: 'ENHANCED',
450+
textareaInfo: textareaInfo
451+
});
452+
window.gitcassoCommentSpots.push(trackingData);
453+
454+
return onEnhanced(spot, textarea);
455+
};
456+
return originalSetEventHandlers.call(this, wrappedOnEnhanced, onDestroyed);
457+
};
458+
}
459+
}, 100);
460+
413461
} catch (error) {
414462
console.error('Failed to execute patched content script:', error);
415463
console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000));
@@ -538,9 +586,31 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
538586
console.log('Spots for display:', spots);
539587
console.log('All textareas on page:', document.querySelectorAll('textarea').length);
540588
541-
const content = spots.length > 0
542-
? \`<div style="font-weight: bold; margin-bottom: 8px; color: #333;">CommentSpots (\${spots.length}):</div><pre style="margin: 0; white-space: pre-wrap;">\${JSON.stringify(spots, null, 2)}</pre>\`
543-
: '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small></div>';
589+
let content = '';
590+
if (spots.length > 0) {
591+
content = \`<div style="font-weight: bold; margin-bottom: 8px; color: #333;">CommentSpots (\${spots.length}):</div>\`;
592+
593+
spots.forEach((spot, index) => {
594+
const hasTextareaInfo = spot.textareaInfo;
595+
const spotData = Object.assign({}, spot);
596+
delete spotData.textareaInfo; // Remove from main display
597+
598+
content += \`<div style="margin-bottom: 12px; padding: 8px; border: 1px solid #eee; border-radius: 4px;">\`;
599+
content += \`<div style="font-weight: bold; color: #555;">Spot \${index + 1}:</div>\`;
600+
content += \`<pre style="margin: 4px 0; font-size: 10px;">\${JSON.stringify(spotData, null, 2)}</pre>\`;
601+
602+
if (hasTextareaInfo) {
603+
content += \`<div style="font-weight: bold; color: #007acc; margin-top: 8px;">Textarea Info:</div>\`;
604+
content += \`<pre style="margin: 4px 0; font-size: 10px; color: #666;">\${JSON.stringify(spot.textareaInfo, null, 2)}</pre>\`;
605+
} else {
606+
content += \`<div style="color: #999; font-style: italic; margin-top: 4px;">No textarea info captured</div>\`;
607+
}
608+
609+
content += \`</div>\`;
610+
});
611+
} else {
612+
content = '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small></div>';
613+
}
544614
545615
commentSpotDisplay.innerHTML = content;
546616
}

0 commit comments

Comments
 (0)