Skip to content

Commit c8b6e8a

Browse files
committed
More progress.
1 parent 219bb10 commit c8b6e8a

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot
1414
spot,
1515
type,
1616
}
17+
18+
// Add textarea debugging info for har:view testing
19+
if (textarea && (window as any).gitcassoDebugMode) {
20+
const rect = textarea.getBoundingClientRect();
21+
(message as any).textareaInfo = {
22+
id: textarea.id || '',
23+
name: textarea.name || '',
24+
className: textarea.className || '',
25+
tagName: textarea.tagName,
26+
placeholder: textarea.placeholder || '',
27+
value: textarea.value ? textarea.value.substring(0, 50) + '...' : '',
28+
parentElement: textarea.parentElement ? textarea.parentElement.tagName + (textarea.parentElement.className ? '.' + textarea.parentElement.className : '') : '',
29+
position: {
30+
top: rect.top,
31+
left: rect.left,
32+
width: rect.width,
33+
height: rect.height
34+
}
35+
};
36+
}
37+
1738
browser.runtime.sendMessage(message).catch((error) => {
1839
logger.debug('Failed to send event to background:', error)
1940
})

browser-extension/tests/har-view.ts

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
360360
console.warn('Failed to patch sendEventToBackground function');
361361
}
362362
363+
// Enable debug mode for textarea info capture
364+
window.gitcassoDebugMode = true;
365+
363366
// Mock necessary APIs before executing
364367
window.chrome = window.chrome || {
365368
runtime: {
@@ -387,6 +390,13 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
387390
timestamp: Date.now(),
388391
action: message.type
389392
});
393+
394+
// Include textarea info if available in the message
395+
if (message.textareaInfo) {
396+
trackingData.textareaInfo = message.textareaInfo;
397+
console.log('Textarea info captured:', message.textareaInfo);
398+
}
399+
390400
window.gitcassoCommentSpots.push(trackingData);
391401
console.log('CommentSpot captured via sendMessage:', trackingData);
392402
console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length);
@@ -404,60 +414,12 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
404414
// Create a global registry to track comment spots for debugging
405415
window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
406416
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-
427417
// Execute the patched script with error handling
428418
try {
429419
const script = document.createElement('script');
430420
script.textContent = patchedCode;
431421
document.head.appendChild(script);
432422
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-
461423
} catch (error) {
462424
console.error('Failed to execute patched content script:', error);
463425
console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000));

0 commit comments

Comments
 (0)