Skip to content

Commit 20dadc0

Browse files
committed
Retry message input dispatch when Meta send button is disabled
- in 'wait until ready', instead of checking if input element includes empty space, check if this button is not disabled: [Pasted text] - at the end of enter message, check if [Pasted text] is no longer disabled, if it is, re-run the input logic after 100ms delay
1 parent 4845f53 commit 20dadc0

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

  • apps/browser/src/content-scripts/send-prompt-content-script/chatbots

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ import {
66
import { report_initialization_error } from '../utils/report-initialization-error'
77

88
export const meta: Chatbot = {
9-
wait_until_ready: async () => {
10-
await new Promise((resolve) => {
11-
const check_for_element = () => {
12-
if (
13-
document.querySelector(
14-
'div[contenteditable="true"][data-testid="composer-input"]'
15-
)
16-
) {
17-
resolve(null)
18-
} else {
19-
setTimeout(check_for_element, 100)
20-
}
21-
}
22-
check_for_element()
23-
})
24-
await new Promise((resolve) => setTimeout(resolve, 500))
25-
},
269
enter_message: async (params) => {
2710
const input_element = document.querySelector(
2811
'div[contenteditable="true"][data-testid="composer-input"]'
@@ -36,14 +19,27 @@ export const meta: Chatbot = {
3619
return
3720
}
3821

39-
input_element.dispatchEvent(
40-
new InputEvent('input', {
41-
bubbles: true,
42-
cancelable: true,
43-
inputType: 'insertText',
44-
data: params.message
45-
})
46-
)
22+
const dispatch_input = () => {
23+
input_element.dispatchEvent(
24+
new InputEvent('input', {
25+
bubbles: true,
26+
cancelable: true,
27+
inputType: 'insertText',
28+
data: params.message
29+
})
30+
)
31+
}
32+
33+
dispatch_input()
34+
35+
const send_button = document.querySelector(
36+
'button[data-testid="composer-send-button"]'
37+
) as HTMLButtonElement
38+
39+
if (send_button && send_button.disabled) {
40+
await new Promise((resolve) => setTimeout(resolve, 100))
41+
dispatch_input()
42+
}
4743
},
4844
setup_observer: (params) => {
4945
const add_buttons = (footer: Element) => {

0 commit comments

Comments
 (0)