Skip to content

Commit 0ae0c99

Browse files
committed
Add error handling for browser storage operations and runtime messages in content scripts
└── apps └── browser └── src ├── background │ ├── clear-chat-init-data.ts │ ├── config.ts │ ├── keep-alive.ts │ ├── main.ts │ ├── message-handler.ts │ └── websocket.ts ├── content-scripts │ └── send-prompt-content-script │ ├── constants │ │ ├── apply-response-icon.ts │ │ └── dictionary.ts │ ├── send-prompt-content-script.ts │ ├── types │ │ └── chatbot.ts │ └── utils │ ├── add-apply-response-button.ts │ ├── apply-response-styles.ts │ ├── logger.ts │ ├── report-initialization-error.ts │ └── show-response-ready-notification.ts ├── manifest.json └── utils └── is-message.ts
1 parent da7d203 commit 0ae0c99

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎apps/browser/src/content-scripts/send-prompt-content-script/send-prompt-content-script.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,11 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
162162
document.addEventListener('keydown', handle_key_press)
163163
setTimeout(resolve, 2000)
164164
})
165-
browser.runtime.sendMessage<Message>({
166-
action: 'chat-initialized'
167-
})
165+
browser.runtime
166+
.sendMessage<Message>({
167+
action: 'chat-initialized'
168+
})
169+
.catch((e) => console.debug('Failed to send chat-initialized message', e))
168170
}
169171

170172
const main = async () => {
@@ -182,7 +184,13 @@ const main = async () => {
182184
)
183185

184186
const storage_key = `chat-init:${batch_id}`
185-
const storage = await browser.storage.local.get(storage_key)
187+
let storage: any
188+
try {
189+
storage = await browser.storage.local.get(storage_key)
190+
} catch (e) {
191+
console.debug('Failed to get chat init data', e)
192+
return
193+
}
186194
const stored_data = storage[storage_key] as {
187195
text: string
188196
current_chat: Chat
@@ -212,7 +220,11 @@ const main = async () => {
212220
chat: current_chat
213221
})
214222

215-
await browser.storage.local.remove(storage_key)
223+
try {
224+
await browser.storage.local.remove(storage_key)
225+
} catch (e) {
226+
console.debug('Failed to remove chat init data', e)
227+
}
216228

217229
if (chatbot?.setup_observer) {
218230
const inject_button = stored_data.inject_apply_response_button ?? false

‎apps/browser/src/content-scripts/send-prompt-content-script/utils/add-apply-response-button.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ export function add_apply_response_button(params: {
5252
console.error('Error reading CWC session data', error)
5353
}
5454

55-
browser.runtime.sendMessage<Message>({
56-
action: 'apply-response',
57-
client_id,
58-
raw_instructions
59-
})
55+
browser.runtime
56+
.sendMessage<Message>({
57+
action: 'apply-response',
58+
client_id,
59+
raw_instructions
60+
})
61+
.catch((e) => console.debug('Failed to send apply-response message', e))
6062
})
6163
})
6264

@@ -89,9 +91,13 @@ export function observe_for_responses(params: {
8991
}
9092

9193
if (!has_sent_finished_responding) {
92-
browser.runtime.sendMessage<Message>({
93-
action: 'finished-responding'
94-
})
94+
browser.runtime
95+
.sendMessage<Message>({
96+
action: 'finished-responding'
97+
})
98+
.catch((e) =>
99+
console.debug('Failed to send finished-responding message', e)
100+
)
95101
has_sent_finished_responding = true
96102
show_response_ready_notification({ chatbot_name: params.chatbot_name })
97103
}

‎apps/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Autofill for Code Web Chat",
55
"short_name": "CWC",
66
"description": "Got tired with copy and paste? Enable prompt autofill!",
7-
"version": "2026.916.10",
7+
"version": "2026.916.11",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

0 commit comments

Comments
 (0)