@@ -5,11 +5,9 @@ import { logger } from '../../lib/logger'
55
66// Test basic DOM access
77try {
8- const app = document . getElementById ( 'app' )
8+ const app = document . getElementById ( 'app' ) ! !
99 logger . debug ( 'Found app element:' , app )
10- if ( app ) {
11- app . innerHTML = '<div>Script is running...</div>'
12- }
10+ app . innerHTML = '<div>Script is running...</div>'
1311} catch ( error ) {
1412 logger . error ( 'Error accessing DOM:' , error )
1513}
@@ -28,9 +26,14 @@ async function getOpenSpots(): Promise<CommentState[]> {
2826 }
2927}
3028
31- async function switchToTab ( tabId : number , windowId : number ) : Promise < void > {
32- await browser . windows . update ( windowId , { focused : true } )
33- await browser . tabs . update ( tabId , { active : true } )
29+ function switchToTab ( tabId : number , windowId : number ) : void {
30+ // Send message to background script to handle tab switching
31+ // This avoids the popup context being destroyed before completion
32+ browser . runtime . sendMessage ( {
33+ type : 'SWITCH_TO_TAB' ,
34+ tabId,
35+ windowId
36+ } )
3437 window . close ( )
3538}
3639
@@ -40,23 +43,18 @@ function createSpotElement(commentState: CommentState): HTMLElement {
4043
4144 logger . debug ( 'Creating spot element for:' , commentState . spot )
4245 const enhancer = enhancers . enhancerFor ( commentState . spot )
43- logger . debug ( 'Found enhancer:' , enhancer )
46+ if ( ! enhancer ) {
47+ logger . error ( 'No enhancer found for:' , commentState . spot )
48+ logger . error ( 'Only have enhancers for:' , enhancers . byType )
49+ }
4450
4551 const title = document . createElement ( 'div' )
4652 title . className = 'spot-title'
47-
48- if ( enhancer ) {
49- title . textContent = enhancer . tableTitle ( commentState . spot )
50- } else {
51- title . textContent = `${ commentState . spot . type } (${ commentState . spot . unique_key } )`
52- }
53-
53+ title . textContent = enhancer . tableTitle ( commentState . spot )
5454 item . appendChild ( title )
55-
5655 item . addEventListener ( 'click' , ( ) => {
5756 switchToTab ( commentState . tab . tabId , commentState . tab . windowId )
5857 } )
59-
6058 return item
6159}
6260
0 commit comments