mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
feat: 初步支持 Gemini 网页版
This commit is contained in:
@@ -131,9 +131,9 @@ export function getHumanClickPoint(box, type = 'random') {
|
||||
|
||||
/**
|
||||
* 安全点击元素 (包含拟人化移动和点击)
|
||||
* 支持 CSS selector 和 ElementHandle 两种输入
|
||||
* 支持 CSS selector、ElementHandle 和 Locator 三种输入
|
||||
* @param {import('playwright-core').Page} page - Playwright 页面对象
|
||||
* @param {string|import('playwright-core').ElementHandle} target - CSS 选择器或元素句柄
|
||||
* @param {string|import('playwright-core').ElementHandle|import('playwright-core').Locator} target - CSS 选择器、元素句柄或 Locator
|
||||
* @param {object} [options] - 点击选项
|
||||
* @param {string} [options.bias='random'] - 偏移偏好: 'input' 或 'random'
|
||||
* @returns {Promise<void>}
|
||||
@@ -142,11 +142,17 @@ export async function safeClick(page, target, options = {}) {
|
||||
try {
|
||||
let el;
|
||||
|
||||
// 判断是 selector 还是 ElementHandle
|
||||
// 判断输入类型
|
||||
if (typeof target === 'string') {
|
||||
// CSS selector
|
||||
el = await page.$(target);
|
||||
if (!el) throw new Error(`未找到: ${target}`);
|
||||
} else if (typeof target.elementHandle === 'function') {
|
||||
// Locator (来自 page.getByRole, page.getByText 等)
|
||||
el = await target.elementHandle();
|
||||
if (!el) throw new Error(`Locator 未匹配到元素`);
|
||||
} else {
|
||||
// ElementHandle
|
||||
el = target;
|
||||
if (!el || !el.asElement()) throw new Error(`Element handle invalid`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user