Skip to content

Commit 25b46a7

Browse files
committed
This has plenty of problems, but it does turn on!
1 parent 7627253 commit 25b46a7

File tree

1 file changed

+36
-11
lines changed
  • browser-extension/src/entrypoints/popup

1 file changed

+36
-11
lines changed

browser-extension/src/entrypoints/popup/main.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@ import type { CommentState } from '../background'
33
import { EnhancerRegistry } from '../../lib/registries'
44
import { logger } from '../../lib/logger'
55

6+
// Test basic DOM access
7+
try {
8+
const app = document.getElementById('app')
9+
logger.debug('Found app element:', app)
10+
if (app) {
11+
app.innerHTML = '<div>Script is running...</div>'
12+
}
13+
} catch (error) {
14+
logger.error('Error accessing DOM:', error)
15+
}
16+
617
const enhancers = new EnhancerRegistry()
718

819
async function getOpenSpots(): Promise<CommentState[]> {
9-
return new Promise((resolve) => {
10-
browser.runtime.sendMessage({ type: 'GET_OPEN_SPOTS' }, (response) => {
11-
resolve(response.spots || [])
12-
})
13-
})
20+
logger.debug('Sending message to background script...')
21+
try {
22+
const response = await browser.runtime.sendMessage({ type: 'GET_OPEN_SPOTS' })
23+
logger.debug('Received response:', response)
24+
return response.spots || []
25+
} catch (error) {
26+
logger.error('Error sending message to background:', error)
27+
return []
28+
}
1429
}
1530

1631
async function switchToTab(tabId: number, windowId: number): Promise<void> {
@@ -23,11 +38,18 @@ function createSpotElement(commentState: CommentState): HTMLElement {
2338
const item = document.createElement('div')
2439
item.className = 'spot-item'
2540

41+
logger.debug('Creating spot element for:', commentState.spot)
42+
const enhancer = enhancers.enhancerFor(commentState.spot)
43+
logger.debug('Found enhancer:', enhancer)
44+
2645
const title = document.createElement('div')
2746
title.className = 'spot-title'
2847

29-
const enhancer = enhancers.enhancerFor(commentState.spot)
30-
title.textContent = enhancer.tableTitle(commentState.spot)
48+
if (enhancer) {
49+
title.textContent = enhancer.tableTitle(commentState.spot)
50+
} else {
51+
title.textContent = `${commentState.spot.type} (${commentState.spot.unique_key})`
52+
}
3153

3254
item.appendChild(title)
3355

@@ -39,11 +61,10 @@ function createSpotElement(commentState: CommentState): HTMLElement {
3961
}
4062

4163
async function renderOpenSpots(): Promise<void> {
42-
logger.debug('renderOpenSpots')
64+
logger.debug('renderOpenSpots called')
4365
const app = document.getElementById('app')!
44-
logger.debug('waiting on getOpenSpots')
4566
const spots = await getOpenSpots()
46-
logger.debug('got', spots)
67+
logger.debug('Got spots:', spots)
4768

4869
if (spots.length === 0) {
4970
app.innerHTML = '<div class="no-spots">No open comment spots</div>'
@@ -64,4 +85,8 @@ async function renderOpenSpots(): Promise<void> {
6485
app.appendChild(list)
6586
}
6687

67-
renderOpenSpots()
88+
renderOpenSpots().catch(error => {
89+
logger.error('Error in renderOpenSpots:', error)
90+
const app = document.getElementById('app')!
91+
app.innerHTML = `<div class="no-spots">Error loading spots: ${error.message}</div>`
92+
})

0 commit comments

Comments
 (0)