feat: implement HumanTyping module to enhance typing simulation and avoid bot detection

This commit is contained in:
2025-12-06 15:02:08 +01:00
parent 067c1989e2
commit b783f7c1fa
6 changed files with 196 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import { Workers } from '../Workers'
import { AxiosRequestConfig } from 'axios'
import { Counters, DashboardData } from '../../interface/DashboardData'
import { GoogleSearch } from '../../interface/Search'
import { HumanTyping } from '../../util/browser/HumanTyping'
import { waitForElementSmart } from '../../util/browser/SmartWait'
type GoogleTrendsResponse = [
@@ -232,15 +233,18 @@ export class Search extends Workers {
let navigatedDirectly = false
try {
// Try focusing and filling instead of clicking (more reliable on mobile)
// FIXED: Use HumanTyping instead of .fill() to avoid bot detection
await box.focus({ timeout: 2000 }).catch(() => { /* ignore focus errors */ })
await box.fill('')
await this.bot.utils.wait(200)
// Clear field using keyboard (natural)
await searchPage.keyboard.down(platformControlKey)
await searchPage.keyboard.press('A')
await searchPage.keyboard.press('Backspace')
await searchPage.keyboard.up(platformControlKey)
await box.type(query, { delay: 20 })
// FIXED: Use HumanTyping for natural search query entry
await HumanTyping.type(box, query, 1.5) // Fast typing (familiar search action)
await searchPage.keyboard.press('Enter')
} catch (typeErr) {
// As a robust fallback, navigate directly to the search results URL

View File

@@ -3,6 +3,7 @@ import path from 'path'
import type { Page } from 'playwright'
import { DELAYS } from '../../constants'
import { HumanTyping } from '../../util/browser/HumanTyping'
import { Workers } from '../Workers'
import { MorePromotion, PromotionalItem } from '../../interface/DashboardData'
@@ -27,9 +28,10 @@ export class SearchOnBing extends Workers {
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_FOCUS)
try {
await box.focus({ timeout: DELAYS.THIS_OR_THAT_START }).catch(() => { /* ignore */ })
await box.fill('')
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_FOCUS)
await page.keyboard.type(query, { delay: DELAYS.TYPING_DELAY })
// FIXED: Use HumanTyping instead of .fill() to avoid bot detection
await HumanTyping.type(box, query, 1.5) // Fast typing (familiar search action)
await page.keyboard.press('Enter')
} catch {
const url = `https://www.bing.com/search?q=${encodeURIComponent(query)}`