yiyan-browser-agent 1.0.9 → 1.0.11
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 +25 -16
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -135,14 +135,12 @@ class YiyanBrowser {
|
|
|
135
135
|
|
|
136
136
|
async _navigate(url) {
|
|
137
137
|
try {
|
|
138
|
-
//
|
|
139
|
-
await this.page.goto(url, { waitUntil: '
|
|
140
|
-
//
|
|
141
|
-
await this.page.waitForTimeout(800);
|
|
138
|
+
// Fast navigation - domcontentloaded is faster than networkidle
|
|
139
|
+
await this.page.goto(url, { waitUntil: 'domcontentloaded', timeout: 15_000 });
|
|
140
|
+
await this.page.waitForTimeout(300); // Minimal wait for SPA render
|
|
142
141
|
} catch (err) {
|
|
143
142
|
logger.warn(`Navigation warning: ${err.message}`);
|
|
144
|
-
|
|
145
|
-
await this.page.waitForTimeout(2000);
|
|
143
|
+
await this.page.waitForTimeout(800);
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
|
|
@@ -150,10 +148,10 @@ class YiyanBrowser {
|
|
|
150
148
|
try {
|
|
151
149
|
for (const sel of SEL.newChat) {
|
|
152
150
|
try {
|
|
153
|
-
const el = await this.page.waitForSelector(sel, { timeout:
|
|
151
|
+
const el = await this.page.waitForSelector(sel, { timeout: 1_500, state: 'visible' });
|
|
154
152
|
if (el) {
|
|
155
153
|
await el.click();
|
|
156
|
-
await this.page.waitForTimeout(
|
|
154
|
+
await this.page.waitForTimeout(200);
|
|
157
155
|
logger.dim('Started new chat session');
|
|
158
156
|
return;
|
|
159
157
|
}
|
|
@@ -168,9 +166,8 @@ class YiyanBrowser {
|
|
|
168
166
|
// ── Login handling (optimized) ─────────────────────────────────────────────
|
|
169
167
|
|
|
170
168
|
async _ensureLoggedIn() {
|
|
171
|
-
//
|
|
172
|
-
await this.page.
|
|
173
|
-
await this.page.waitForTimeout(500);
|
|
169
|
+
// Quick check, no unnecessary waiting
|
|
170
|
+
await this.page.waitForTimeout(200);
|
|
174
171
|
|
|
175
172
|
const needsLogin = await this.page.evaluate(() => {
|
|
176
173
|
const url = window.location.href;
|
|
@@ -190,7 +187,7 @@ class YiyanBrowser {
|
|
|
190
187
|
if (needsLogin) {
|
|
191
188
|
this._printLoginBanner();
|
|
192
189
|
await this._waitForEnter();
|
|
193
|
-
await this.page.waitForNavigation({ waitUntil: '
|
|
190
|
+
await this.page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 15_000 }).catch(() => {});
|
|
194
191
|
}
|
|
195
192
|
}
|
|
196
193
|
|
|
@@ -235,15 +232,14 @@ class YiyanBrowser {
|
|
|
235
232
|
|
|
236
233
|
// Focus and select all existing content
|
|
237
234
|
await el.click({ clickCount: 3, force: true });
|
|
238
|
-
await this.page.waitForTimeout(
|
|
235
|
+
await this.page.waitForTimeout(100);
|
|
239
236
|
|
|
240
237
|
// Clear by pressing Delete
|
|
241
238
|
await this.page.keyboard.press('Delete');
|
|
242
|
-
await this.page.waitForTimeout(
|
|
239
|
+
await this.page.waitForTimeout(50);
|
|
243
240
|
|
|
244
241
|
// Type text character by character (stable, works reliably)
|
|
245
|
-
|
|
246
|
-
await this.page.keyboard.type(text, { delay: 15 });
|
|
242
|
+
await this.page.keyboard.type(text, { delay: 10 });
|
|
247
243
|
|
|
248
244
|
// Press Enter to send
|
|
249
245
|
await this.page.keyboard.press('Enter');
|
|
@@ -512,9 +508,22 @@ class YiyanBrowser {
|
|
|
512
508
|
if (!text) return '';
|
|
513
509
|
|
|
514
510
|
return text
|
|
511
|
+
// Strip AI thinking blocks
|
|
515
512
|
.replace(/<think>[\s\S]*?<\/think>\n?/gi, '')
|
|
513
|
+
// Strip "Thinking..." headers
|
|
516
514
|
.replace(/^Thinking\.{0,3}\n[\s\S]*?\n\n/m, '')
|
|
515
|
+
// Strip "深度思考已完成" and similar
|
|
516
|
+
.replace(/深度思考已完成\n?/g, '')
|
|
517
|
+
.replace(/思考完成[::\s]*[\s\S]*?(?=济宁|[^\n])/g, '')
|
|
518
|
+
// Strip "参考X个网页"
|
|
519
|
+
.replace(/参考\d+个网页\n?/g, '')
|
|
520
|
+
// Strip suggested follow-up questions (Chinese)
|
|
521
|
+
.replace(/请告诉我更多.*$/gm, '')
|
|
522
|
+
.replace(/再多给我一些.*$/gm, '')
|
|
523
|
+
.replace(/再多提供一些.*$/gm, '')
|
|
524
|
+
// Strip copy-code button artifacts
|
|
517
525
|
.replace(/^\d+(?:Copy|Run|Insert|Edit)\b.*$/gm, '')
|
|
526
|
+
// Collapse multiple blank lines
|
|
518
527
|
.replace(/\n{3,}/g, '\n\n')
|
|
519
528
|
.trim();
|
|
520
529
|
}
|