Skip to content

Commit 95c27cc

Browse files
committed
Improve chatbot readiness checks for ChatGPT and Claude
- in `apps/browser/src/content-scripts/send-prompt-content-script/chatbots/claude.ts` implement 'wait until ready' inspired by `apps/browser/src/content-scripts/send-prompt-content-script/chatbots/chatgpt.ts` approach
1 parent 4b0d39b commit 95c27cc

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export const chatgpt: Chatbot = {
1919
input_element.dispatchEvent(new Event('input', { bubbles: true }))
2020

2121
if (input_element.innerText == ' ') {
22-
input_element.innerText = ''
23-
input_element.dispatchEvent(new Event('input', { bubbles: true }))
2422
resolve(null)
2523
return
2624
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ export const claude: Chatbot = {
1010
wait_until_ready: async () => {
1111
await new Promise((resolve) => {
1212
const check_for_element = () => {
13-
if (
14-
document.querySelector(
15-
'div[contenteditable="true"]'
16-
) as HTMLDivElement
17-
) {
18-
resolve(null)
19-
} else {
20-
setTimeout(check_for_element, 100)
13+
const input_element = document.querySelector(
14+
'div[contenteditable=true]'
15+
) as HTMLElement
16+
17+
if (input_element) {
18+
input_element.innerText = ' '
19+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
20+
21+
if (input_element.innerText == ' ') {
22+
resolve(null)
23+
return
24+
}
2125
}
26+
27+
setTimeout(check_for_element, 100)
2228
}
2329
check_for_element()
2430
})
25-
await new Promise((resolve) => setTimeout(resolve, 1000))
2631
},
2732
set_options: async (chat) => {
2833
const options = chat.options

0 commit comments

Comments
 (0)