fix: search like a person — open homepage, type in the site's search box
controlBrowser search opened the results URL directly (search.naver.com?query). Now it navigates to the homepage (www.naver.com / google.com), clicks the on-page search box, types the query char-by-char and presses Enter — real human-style search, visible on screen.
This commit is contained in:
@@ -98,28 +98,47 @@ try {
|
||||
}
|
||||
|
||||
case 'search': {
|
||||
// One-shot "search on a site": build the engine's results URL so a small
|
||||
// model doesn't have to chain navigate->type->enter. Visible on screen.
|
||||
// Search like a PERSON: open the site's main page, click its search box,
|
||||
// type the query char-by-char, press Enter — NOT a direct results-URL.
|
||||
const q = String(cmd.query || '').trim();
|
||||
if (!q) throw new Error('search: no query');
|
||||
const site = String(cmd.site || 'google').toLowerCase();
|
||||
const engines = {
|
||||
naver: 'https://search.naver.com/search.naver?query=',
|
||||
google: 'https://www.google.com/search?q=',
|
||||
daum: 'https://search.daum.net/search?q=',
|
||||
youtube: 'https://www.youtube.com/results?search_query=',
|
||||
bing: 'https://www.bing.com/search?q=',
|
||||
const siteKey = String(cmd.site || 'google').toLowerCase();
|
||||
const SITES = {
|
||||
naver: { home: 'https://www.naver.com', box: '#query, input[name="query"]' },
|
||||
google: { home: 'https://www.google.com', box: 'textarea[name="q"], input[name="q"]' },
|
||||
daum: { home: 'https://www.daum.net', box: '#q, input[name="q"]' },
|
||||
youtube: { home: 'https://www.youtube.com', box: 'input#search, input[name="search_query"]' },
|
||||
bing: { home: 'https://www.bing.com', box: '#sb_form_q, input[name="q"]' },
|
||||
};
|
||||
const base = engines[site] || engines.google;
|
||||
const target = base + encodeURIComponent(q);
|
||||
const s = SITES[siteKey] || SITES.google;
|
||||
await front(page);
|
||||
// 1) Go to the homepage.
|
||||
if (HAS_XDOTOOL && cmd.human !== false) {
|
||||
try { await human.navigateOmnibox(target); await page.waitForLoadState('domcontentloaded').catch(() => {}); }
|
||||
catch { await page.goto(target, { waitUntil: 'domcontentloaded' }); }
|
||||
try { await human.navigateOmnibox(s.home); await page.waitForLoadState('domcontentloaded').catch(() => {}); }
|
||||
catch { await page.goto(s.home, { waitUntil: 'domcontentloaded' }); }
|
||||
} else {
|
||||
await page.goto(target, { waitUntil: 'domcontentloaded' });
|
||||
await page.goto(s.home, { waitUntil: 'domcontentloaded' });
|
||||
}
|
||||
out({ ok: true, site: engines[site] ? site : 'google', query: q, url: page.url(), title: await page.title().catch(() => '') });
|
||||
// 2) Click the on-page search box, type the query, submit.
|
||||
const box = page.locator(s.box).first();
|
||||
await box.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
if (HAS_XDOTOOL && cmd.human !== false) {
|
||||
try {
|
||||
await human.humanClick(page, box);
|
||||
await human.humanType(q);
|
||||
await human.pressKey('Return');
|
||||
} catch {
|
||||
await box.click().catch(() => {});
|
||||
await box.fill(q).catch(() => {});
|
||||
await page.keyboard.press('Enter').catch(() => {});
|
||||
}
|
||||
} else {
|
||||
await box.click().catch(() => {});
|
||||
await box.fill(q);
|
||||
await page.keyboard.press('Enter');
|
||||
}
|
||||
await page.waitForLoadState('domcontentloaded').catch(() => {});
|
||||
out({ ok: true, site: SITES[siteKey] ? siteKey : 'google', query: q, url: page.url(), title: await page.title().catch(() => '') });
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user