Skip to content

Commit 8056bc7

Browse files
committed
Progress.
1 parent 11a9897 commit 8056bc7

File tree

2 files changed

+39
-119
lines changed

2 files changed

+39
-119
lines changed

browser-extension/src/lib/registries.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,8 @@ export class TextareaRegistry {
132132
get(textarea: HTMLTextAreaElement): EnhancedTextarea | undefined {
133133
return this.textareas.get(textarea)
134134
}
135+
136+
getAllEnhanced(): EnhancedTextarea[] {
137+
return Array.from(this.textareas.values())
138+
}
135139
}

browser-extension/tests/har-view.ts

Lines changed: 35 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -337,115 +337,23 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
337337
'console.warn("Webextension-polyfill check bypassed for HAR testing"'
338338
);
339339
340-
// Patch the content script to track CommentSpots globally
341-
console.log('Original code length:', code.length);
342-
console.log('Code sample around sendEventToBackground:',
343-
code.match(/sendEventToBackground[^;}]{0,100}/g) || 'No matches found');
344-
345-
// More flexible regex to match both quote styles and variations
346-
const enhancedMatches = patchedCode.match(/sendEventToBackground\\(['"](ENHANCED)['"], ?spot\\)/g);
347-
const destroyedMatches = patchedCode.match(/sendEventToBackground\\(['"](DESTROYED)['"], ?spot\\)/g);
348-
console.log('ENHANCED matches found:', enhancedMatches?.length || 0);
349-
console.log('DESTROYED matches found:', destroyedMatches?.length || 0);
350-
351-
// Remove complex function patching - we'll use sendMessage interception instead
352-
console.log('Skipping function patching, using sendMessage interception for CommentSpot tracking');
353-
354-
// Verify patches were applied
355-
const functionPatchMatches = patchedCode.match(/window\\.gitcassoCommentSpots.*action: type/g);
356-
console.log('Function patches applied:', functionPatchMatches?.length || 0);
357-
if (functionPatchMatches && functionPatchMatches.length > 0) {
358-
console.log('sendEventToBackground function successfully patched for CommentSpot tracking');
359-
} else {
360-
console.warn('Failed to patch sendEventToBackground function');
361-
}
362-
363-
364340
// Mock necessary APIs before executing
365341
window.chrome = window.chrome || {
366342
runtime: {
367343
getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
368344
onMessage: { addListener: () => {} },
369-
sendMessage: (message) => {
370-
console.log('Mock sendMessage called with:', message);
371-
return Promise.resolve();
372-
},
373-
id: 'gitcasso-test'
374-
}
375-
};
376-
window.browser = window.browser || {
377-
runtime: {
378-
getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
379-
onMessage: { addListener: () => {} },
380-
sendMessage: (message) => {
381-
console.log('Mock browser.runtime.sendMessage called with:', message);
382-
383-
// Track CommentSpots when they're sent via sendMessage
384-
if (message && message.spot && message.type) {
385-
try {
386-
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
387-
388-
// Capture textarea debugging info here instead of in production code
389-
let textareaInfo = null;
390-
if (message.type === 'ENHANCED' && window.gitcassoTextareaRegistry) {
391-
const textareas = document.querySelectorAll('textarea');
392-
for (const textarea of textareas) {
393-
const enhanced = window.gitcassoTextareaRegistry.get(textarea);
394-
if (enhanced && enhanced.spot.unique_key === message.spot.unique_key) {
395-
const rect = textarea.getBoundingClientRect();
396-
textareaInfo = {
397-
id: textarea.id || '',
398-
name: textarea.name || '',
399-
className: textarea.className || '',
400-
tagName: textarea.tagName,
401-
placeholder: textarea.placeholder || '',
402-
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
403-
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
404-
position: {
405-
top: rect.top,
406-
left: rect.left,
407-
width: rect.width,
408-
height: rect.height
409-
}
410-
};
411-
break;
412-
}
413-
}
414-
}
415-
416-
const trackingData = Object.assign({}, message.spot, {
417-
timestamp: Date.now(),
418-
action: message.type,
419-
textareaInfo
420-
});
421-
422-
window.gitcassoCommentSpots.push(trackingData);
423-
console.log('CommentSpot captured via sendMessage:', trackingData);
424-
console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length);
425-
} catch (e) {
426-
console.error('Failed to track CommentSpot via sendMessage:', e);
427-
}
428-
}
429-
430-
return Promise.resolve();
431-
},
345+
sendMessage: () => Promise.resolve(),
432346
id: 'gitcasso-test'
433347
}
434348
};
349+
window.browser = window.chrome;
350+
351+
352+
// Execute the patched script
353+
const script = document.createElement('script');
354+
script.textContent = patchedCode;
355+
document.head.appendChild(script);
435356
436-
// Create a global registry to track comment spots for debugging
437-
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
438-
439-
// Execute the patched script with error handling
440-
try {
441-
const script = document.createElement('script');
442-
script.textContent = patchedCode;
443-
document.head.appendChild(script);
444-
console.log('Content script executed successfully');
445-
} catch (error) {
446-
console.error('Failed to execute patched content script:', error);
447-
console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000));
448-
}
449357
450358
console.log('Gitcasso content script loaded with location patching for:', '${urlParts.href}');
451359
})
@@ -571,30 +479,44 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
571479
empty: 'color: #666; font-style: italic;'
572480
};
573481
574-
function formatSpot(spot, index) {
575-
const { textareaInfo, ...spotData } = spot;
482+
function formatSpot(enhanced, index) {
483+
const { textarea, spot } = enhanced;
484+
const rect = textarea.getBoundingClientRect();
485+
const textareaInfo = {
486+
id: textarea.id || '',
487+
name: textarea.name || '',
488+
className: textarea.className || '',
489+
tagName: textarea.tagName,
490+
placeholder: textarea.placeholder || '',
491+
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
492+
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
493+
position: {
494+
top: rect.top,
495+
left: rect.left,
496+
width: rect.width,
497+
height: rect.height
498+
}
499+
};
500+
576501
return \`
577502
<div style="\${styles.spotContainer}">
578503
<div style="\${styles.spotTitle}">Spot \${index + 1}:</div>
579-
<pre style="\${styles.jsonPre}">\${JSON.stringify(spotData, null, 2)}</pre>
580-
\${textareaInfo
581-
? \`<div style="\${styles.textareaHeader}">Textarea Info:</div>
582-
<pre style="\${styles.textareaPre}">\${JSON.stringify(textareaInfo, null, 2)}</pre>\`
583-
: \`<div style="\${styles.noInfo}">No textarea info captured</div>\`
584-
}
504+
<pre style="\${styles.jsonPre}">\${JSON.stringify(spot, null, 2)}</pre>
505+
<div style="\${styles.textareaHeader}">Textarea Info:</div>
506+
<pre style="\${styles.textareaPre}">\${JSON.stringify(textareaInfo, null, 2)}</pre>
585507
</div>
586508
\`;
587509
}
588510
589511
function updateCommentSpotDisplay() {
590-
const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : [];
512+
const enhanced = window.enhancedTextareas ? window.enhancedTextareas.getAllEnhanced() : [];
591513
592-
console.log('Spots for display:', spots);
514+
console.log('Enhanced textareas:', enhanced.length);
593515
console.log('All textareas on page:', document.querySelectorAll('textarea').length);
594516
595-
const content = spots.length > 0
596-
? \`<div style="\${styles.header}">CommentSpots (\${spots.length}):</div>
597-
\${spots.map(formatSpot).join('')}\`
517+
const content = enhanced.length > 0
518+
? \`<div style="\${styles.header}">CommentSpots (\${enhanced.length}):</div>
519+
\${enhanced.map(formatSpot).join('')}\`
598520
: \`<div style="\${styles.empty}">No CommentSpots detected yet...<br><small>Textareas found: \${document.querySelectorAll('textarea').length}</small></div>\`;
599521
600522
commentSpotDisplay.innerHTML = content;
@@ -607,12 +529,6 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
607529
setInterval(updateCommentSpotDisplay, 2000);
608530
609531
document.body.appendChild(commentSpotDisplay);
610-
611-
// Expose textarea registry access function globally
612-
window.gitcassoGetCommentSpots = function() {
613-
// Return the global comment spots array
614-
return window.gitcassoCommentSpots || [];
615-
};
616532
</script>
617533
`
618534
if (!html.includes('</body>')) {

0 commit comments

Comments
 (0)