11import { CONFIG } from '../lib/config'
2- import type { CommentEvent , CommentSpot } from '../lib/enhancer'
2+ import type { CommentEvent , CommentSpot , StrippedLocation } from '../lib/enhancer'
33import { logger } from '../lib/logger'
44import { EnhancerRegistry , TextareaRegistry } from '../lib/registries'
55
@@ -9,6 +9,18 @@ const enhancedTextareas = new TextareaRegistry()
99// Expose for debugging in har:view
1010; ( window as any ) . gitcassoTextareaRegistry = enhancedTextareas
1111
12+ function detectLocation ( ) : StrippedLocation {
13+ if ( ( window as any ) . gitcassoMockLocation ) {
14+ return ( window as any ) . gitcassoMockLocation
15+ }
16+ const result = {
17+ host : window . location . host ,
18+ pathname : window . location . pathname ,
19+ }
20+ logger . debug ( '[gitcasso] detectLocation called, returning:' , result )
21+ return result
22+ }
23+
1224function sendEventToBackground ( type : 'ENHANCED' | 'DESTROYED' , spot : CommentSpot ) : void {
1325 const message : CommentEvent = {
1426 spot,
@@ -26,6 +38,7 @@ enhancedTextareas.setEventHandlers(
2638
2739export default defineContentScript ( {
2840 main ( ) {
41+ logger . debug ( 'Main was called' )
2942 const textAreasOnPageLoad = document . querySelectorAll < HTMLTextAreaElement > ( `textarea` )
3043 for ( const textarea of textAreasOnPageLoad ) {
3144 enhanceMaybe ( textarea )
@@ -35,7 +48,7 @@ export default defineContentScript({
3548 childList : true ,
3649 subtree : true ,
3750 } )
38- logger . debug ( 'Extension loaded with' , enhancers . getEnhancerCount , 'handlers' )
51+ logger . debug ( 'Extension loaded with' , enhancers . getEnhancerCount ( ) , 'handlers' )
3952 } ,
4053 matches : [ '<all_urls>' ] ,
4154 runAt : 'document_end' ,
@@ -80,6 +93,7 @@ function handleMutations(mutations: MutationRecord[]): void {
8093}
8194
8295function enhanceMaybe ( textarea : HTMLTextAreaElement ) {
96+ logger . debug ( '[gitcasso] enhanceMaybe called for textarea:' , textarea . id , textarea . className )
8397 if ( enhancedTextareas . get ( textarea ) ) {
8498 logger . debug ( 'textarea already registered {}' , textarea )
8599 return
@@ -89,7 +103,9 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) {
89103 injectStyles ( )
90104
91105 try {
92- const enhancedTextarea = enhancers . tryToEnhance ( textarea )
106+ const location = detectLocation ( )
107+ logger . debug ( '[gitcasso] Calling tryToEnhance with location:' , location )
108+ const enhancedTextarea = enhancers . tryToEnhance ( textarea , location )
93109 if ( enhancedTextarea ) {
94110 logger . debug (
95111 'Identified textarea:' ,
0 commit comments