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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/browser.js +9 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "AI coding agent powered by Yiyan (文心一言) via browser automation — no API key needed",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/browser.js CHANGED
@@ -228,51 +228,21 @@ class YiyanBrowser {
228
228
  });
229
229
  }
230
230
 
231
- // ── Sending Messages (optimized: paste instead of type) ────────────────────
231
+ // ── Sending Messages (stable: keyboard.type) ────────────────────────────────
232
232
 
233
233
  async sendMessage(text) {
234
234
  const { el } = await this._findInput();
235
235
 
236
- // Focus the element
237
- await el.focus();
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 existing content
240
- await el.evaluate(e => {
241
- e.textContent = '';
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
- // Small delay to let UI process the input
275
- await this.page.waitForTimeout(50);
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');