@@ -338,38 +338,82 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
338338 );
339339
340340 // Patch the content script to track CommentSpots globally
341- patchedCode = patchedCode.replace(
342- /sendEventToBackground\\('ENHANCED', spot\\)/g,
343- \`sendEventToBackground('ENHANCED', spot);
344- window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
345- window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'ENHANCED'});\`
346- );
347-
348- patchedCode = patchedCode.replace(
349- /sendEventToBackground\\('DESTROYED', spot\\)/g,
350- \`sendEventToBackground('DESTROYED', spot);
351- window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
352- window.gitcassoCommentSpots.push({...spot, timestamp: Date.now(), action: 'DESTROYED'});\`
353- );
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+ }
354362
355363 // Mock necessary APIs before executing
356364 window.chrome = window.chrome || {
357365 runtime: {
358366 getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
359367 onMessage: { addListener: () => {} },
360- sendMessage: () => Promise.resolve(),
368+ sendMessage: (message) => {
369+ console.log('Mock sendMessage called with:', message);
370+ return Promise.resolve();
371+ },
372+ id: 'gitcasso-test'
373+ }
374+ };
375+ window.browser = window.browser || {
376+ runtime: {
377+ getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
378+ onMessage: { addListener: () => {} },
379+ sendMessage: (message) => {
380+ console.log('Mock browser.runtime.sendMessage called with:', message);
381+
382+ // Track CommentSpots when they're sent via sendMessage
383+ if (message && message.spot && message.type) {
384+ try {
385+ window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
386+ const trackingData = Object.assign({}, message.spot, {
387+ timestamp: Date.now(),
388+ action: message.type
389+ });
390+ window.gitcassoCommentSpots.push(trackingData);
391+ console.log('CommentSpot captured via sendMessage:', trackingData);
392+ console.log('Total CommentSpots tracked:', window.gitcassoCommentSpots.length);
393+ } catch (e) {
394+ console.error('Failed to track CommentSpot via sendMessage:', e);
395+ }
396+ }
397+
398+ return Promise.resolve();
399+ },
361400 id: 'gitcasso-test'
362401 }
363402 };
364- window.browser = window.chrome;
365403
366404 // Create a global registry to track comment spots for debugging
367405 window.gitcassoCommentSpots = window.gitcassoCommentSpots || [];
368406
369- // Execute the patched script
370- const script = document.createElement('script');
371- script.textContent = patchedCode;
372- document.head.appendChild(script);
407+ // Execute the patched script with error handling
408+ try {
409+ const script = document.createElement('script');
410+ script.textContent = patchedCode;
411+ document.head.appendChild(script);
412+ console.log('Content script executed successfully');
413+ } catch (error) {
414+ console.error('Failed to execute patched content script:', error);
415+ console.log('First 1000 chars of patched code:', patchedCode.substring(0, 1000));
416+ }
373417
374418 console.log('Gitcasso content script loaded with location patching for:', '${ urlParts . href } ');
375419 })
@@ -487,9 +531,16 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
487531 function updateCommentSpotDisplay() {
488532 const spots = window.gitcassoGetCommentSpots ? window.gitcassoGetCommentSpots() : [];
489533
534+ // Debug logging
535+ if (window.gitcassoCommentSpots) {
536+ console.log('Raw gitcassoCommentSpots array:', window.gitcassoCommentSpots);
537+ }
538+ console.log('Spots for display:', spots);
539+ console.log('All textareas on page:', document.querySelectorAll('textarea').length);
540+
490541 const content = spots.length > 0
491542 ? \`<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>\`
492- : '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...</div>';
543+ : '<div style="color: #666; font-style: italic;">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small>< /div>';
493544
494545 commentSpotDisplay.innerHTML = content;
495546 }
0 commit comments