|
|
(function sendRealInput(text) {
// 1️⃣ 获取输入框
const textarea = document.querySelector('textarea[placeholder*="发消息"]');
if (!textarea) return console.error('❌ 未找到输入框');
// 2️⃣ 使用原生 input setter 更新 value
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLTextAreaElement.prototype,
"value"
).set;
nativeInputValueSetter.call(textarea, text);
// 3️⃣ 触发 React 监听的 input 事件
const inputEvent = new Event('input', { bubbles: true });
textarea.dispatchEvent(inputEvent);
// 4️⃣ 模拟按下 Enter 发送
textarea.dispatchEvent(new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
key: 'Enter',
code: 'Enter'
}));
console.log('✅ 已真正发送:', text);
})('测试成功!');
F12,控制台运行就可以了 |
|