yiyan-browser-agent 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/browser.js +9 -39
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -228,51 +228,21 @@ class YiyanBrowser {
|
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
// ── Sending Messages (
|
|
231
|
+
// ── Sending Messages (stable: keyboard.type) ────────────────────────────────
|
|
232
232
|
|
|
233
233
|
async sendMessage(text) {
|
|
234
234
|
const { el } = await this._findInput();
|
|
235
235
|
|
|
236
|
-
// Focus
|
|
237
|
-
await el.
|
|
236
|
+
// Focus and select all existing content
|
|
237
|
+
await el.click({ clickCount: 3, force: true });
|
|
238
|
+
await this.page.waitForTimeout(200);
|
|
238
239
|
|
|
239
|
-
// Clear
|
|
240
|
-
await
|
|
241
|
-
|
|
242
|
-
if (e.innerText) e.innerText = '';
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// Use clipboard paste for instant input (much faster than typing)
|
|
246
|
-
await this.page.evaluate(async (text) => {
|
|
247
|
-
// Try modern clipboard API first
|
|
248
|
-
try {
|
|
249
|
-
await navigator.clipboard.writeText(text);
|
|
250
|
-
document.execCommand('paste');
|
|
251
|
-
return;
|
|
252
|
-
} catch {}
|
|
253
|
-
|
|
254
|
-
// Fallback: direct DOM manipulation with proper event dispatch
|
|
255
|
-
const activeEl = document.activeElement;
|
|
256
|
-
if (activeEl && activeEl.isContentEditable) {
|
|
257
|
-
activeEl.textContent = text;
|
|
258
|
-
|
|
259
|
-
// Dispatch input event so Yiyan recognizes the content
|
|
260
|
-
const inputEvent = new InputEvent('input', {
|
|
261
|
-
bubbles: true,
|
|
262
|
-
cancelable: true,
|
|
263
|
-
inputType: 'insertText',
|
|
264
|
-
data: text,
|
|
265
|
-
});
|
|
266
|
-
activeEl.dispatchEvent(inputEvent);
|
|
267
|
-
|
|
268
|
-
// Also dispatch change event for good measure
|
|
269
|
-
const changeEvent = new Event('change', { bubbles: true });
|
|
270
|
-
activeEl.dispatchEvent(changeEvent);
|
|
271
|
-
}
|
|
272
|
-
}, text);
|
|
240
|
+
// Clear by pressing Delete
|
|
241
|
+
await this.page.keyboard.press('Delete');
|
|
242
|
+
await this.page.waitForTimeout(100);
|
|
273
243
|
|
|
274
|
-
//
|
|
275
|
-
await this.page.
|
|
244
|
+
// Type text character by character (stable, works reliably)
|
|
245
|
+
await this.page.keyboard.type(text, { delay: 30 });
|
|
276
246
|
|
|
277
247
|
// Press Enter to send
|
|
278
248
|
await this.page.keyboard.press('Enter');
|