Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
适配:补充百度贴吧点赞控件识别
16Mikuf15b81daed1e
diff --git a/src/chrome/src/agent/adapters.js b/src/chrome/src/agent/adapters.jsindex 13910fa2c..138d35602 100644--- a/src/chrome/src/agent/adapters.js+++ b/src/chrome/src/agent/adapters.js@@ -15734,6 +15734,12 @@ function isDirectBaiduSearchUrl(url) {return host === 'news.baidu.com' && /^\/ns(?:\/|$)/.test(path);}+function isBaiduTiebaUrl(url) {+ const parts = adapterUrlParts(url);+ if (!parts) return false;+ return normalizedHostname(parts.parsed.hostname) === 'tieba.baidu.com';+}+function isBaiduSearchUrl(url) {if (isDirectBaiduSearchUrl(url)) return true;let parts;@@ -16139,6 +16145,17 @@ const ADAPTERS = [- Use image or video cards only after opening the source page or detail view; thumbnails, captions, and neighboring card text can be mismatched or truncated, and lazy-loaded card indices are not stable after scrolling.- Read-only web search and result opening do not require sign-in. If "登录" or "扫码登录" appears, ask the user to authenticate only for an explicitly requested account feature; do not block ordinary search, loop on the dialog, or claim that login is required for public results.- If wappass.baidu.com/static/captcha shows "百度安全验证", stop and ask the user to complete it manually. After completion, continue the encoded backurl and re-read the results; do not bypass the challenge, discard the query, or loop on the search URL.`,+ },+ {+ name: 'baidu-tieba',+ category: 'general',+ matches: isBaiduTiebaUrl,+ notes: `+- Tieba thread pages use a custom Vue action bar. On the first floor, the share, reply, like, and collect actions are icon-plus-count elements rather than native buttons; use the accessibility tree or interactive-element list and prefer the named "点赞" control over screenshot coordinates.+- Reply-level likes are separate "赞" controls in each comment row. Re-read the active post or comment container after scrolling, switching "只看楼主", or changing 热门/正序/倒序; indices and visible rows can change.+- "点赞", "关注", "回复", and "发贴" change account or public state. Perform them only when explicitly requested, then verify the icon/count or resulting state; a successful mouse dispatch alone is not proof.+- The first-floor action bar may be below the initial viewport, while images open a viewer when clicked. Do not click nearby image coordinates or repeat a coordinate after an unexpected viewer opens; close or go back, then re-read the page.+- Public pages may require Baidu sign-in. If "登录", QR verification, or "百度安全验证" appears, stop for the user and do not bypass, retry, or claim that the requested action succeeded.`,},{name: 'slack',diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex 524d20132..70c2215df 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -2920,6 +2920,9 @@ export class CDPClient {['.follow-wrapper', '关注'], ['.follow-btn', '关注'],['.follow-button', '关注'], ['.send-btn', '发布评论'],['.publish-btn', '发布'], ['.publish-button', '发布'],+ ] : onHost('tieba.baidu.com') ? [+ ['.pc-pb-first-floor-interactive .action-item:has(use[*|href="#agree_pb"])', '点赞'],+ ['.pc-pb-comments-desc .zan-container-dark:has(use[*|href="#agree_comment"])', '赞'],] : [];const SELECTORS = ['a[href]', 'button', 'input:not([type="hidden"])', 'textarea', 'select',diff --git a/src/chrome/src/content/accessibility-tree.js b/src/chrome/src/content/accessibility-tree.jsindex 7b881a054..ca0dc8d41 100644--- a/src/chrome/src/content/accessibility-tree.js+++ b/src/chrome/src/content/accessibility-tree.js@@ -155,6 +155,10 @@['.publish-btn', '发布'],['.publish-button', '发布'],],+ baiduTieba: [+ ['.pc-pb-first-floor-interactive .action-item:has(use[*|href="#agree_pb"])', '点赞'],+ ['.pc-pb-comments-desc .zan-container-dark:has(use[*|href="#agree_comment"])', '赞'],+ ],};function currentSiteInteractionConfig() {@@ -162,6 +166,7 @@const onHost = (domain) => hostname === domain || hostname.endsWith(`.${domain}`);if (onHost('bilibili.com')) return { key: 'bilibili', rules: SITE_INTERACTION_RULES.bilibili };if (onHost('xiaohongshu.com')) return { key: 'xiaohongshu', rules: SITE_INTERACTION_RULES.xiaohongshu };+ if (onHost('tieba.baidu.com')) return { key: 'baiduTieba', rules: SITE_INTERACTION_RULES.baiduTieba };// LinkedIn's interop shell renders major surfaces (the post composer// dialog among them) inside the open #interop-outlet shadow root. No// custom interaction rules needed — piercing alone makes the dialog'sdiff --git a/src/firefox/src/agent/adapters.js b/src/firefox/src/agent/adapters.jsindex be84fa4e4..d1226bb4a 100644--- a/src/firefox/src/agent/adapters.js+++ b/src/firefox/src/agent/adapters.js@@ -15734,6 +15734,12 @@ function isDirectBaiduSearchUrl(url) {return host === 'news.baidu.com' && /^\/ns(?:\/|$)/.test(path);}+function isBaiduTiebaUrl(url) {+ const parts = adapterUrlParts(url);+ if (!parts) return false;+ return normalizedHostname(parts.parsed.hostname) === 'tieba.baidu.com';+}+function isBaiduSearchUrl(url) {if (isDirectBaiduSearchUrl(url)) return true;let parts;@@ -16138,6 +16144,17 @@ const ADAPTERS = [- Use image or video cards only after opening the source page or detail view; thumbnails, captions, and neighboring card text can be mismatched or truncated, and lazy-loaded card indices are not stable after scrolling.- Read-only web search and result opening do not require sign-in. If "登录" or "扫码登录" appears, ask the user to authenticate only for an explicitly requested account feature; do not block ordinary search, loop on the dialog, or claim that login is required for public results.- If wappass.baidu.com/static/captcha shows "百度安全验证", stop and ask the user to complete it manually. After completion, continue the encoded backurl and re-read the results; do not bypass the challenge, discard the query, or loop on the search URL.`,+ },+ {+ name: 'baidu-tieba',+ category: 'general',+ matches: isBaiduTiebaUrl,+ notes: `+- Tieba thread pages use a custom Vue action bar. On the first floor, the share, reply, like, and collect actions are icon-plus-count elements rather than native buttons; use the accessibility tree or interactive-element list and prefer the named "点赞" control over screenshot coordinates.+- Reply-level likes are separate "赞" controls in each comment row. Re-read the active post or comment container after scrolling, switching "只看楼主", or changing 热门/正序/倒序; indices and visible rows can change.+- "点赞", "关注", "回复", and "发贴" change account or public state. Perform them only when explicitly requested, then verify the icon/count or resulting state; a successful mouse dispatch alone is not proof.+- The first-floor action bar may be below the initial viewport, while images open a viewer when clicked. Do not click nearby image coordinates or repeat a coordinate after an unexpected viewer opens; close or go back, then re-read the page.+- Public pages may require Baidu sign-in. If "登录", QR verification, or "百度安全验证" appears, stop for the user and do not bypass, retry, or claim that the requested action succeeded.`,},{name: 'slack',diff --git a/src/firefox/src/content/accessibility-tree.js b/src/firefox/src/content/accessibility-tree.jsindex 7b881a054..ca0dc8d41 100644--- a/src/firefox/src/content/accessibility-tree.js+++ b/src/firefox/src/content/accessibility-tree.js@@ -155,6 +155,10 @@['.publish-btn', '发布'],['.publish-button', '发布'],],+ baiduTieba: [+ ['.pc-pb-first-floor-interactive .action-item:has(use[*|href="#agree_pb"])', '点赞'],+ ['.pc-pb-comments-desc .zan-container-dark:has(use[*|href="#agree_comment"])', '赞'],+ ],};function currentSiteInteractionConfig() {@@ -162,6 +166,7 @@const onHost = (domain) => hostname === domain || hostname.endsWith(`.${domain}`);if (onHost('bilibili.com')) return { key: 'bilibili', rules: SITE_INTERACTION_RULES.bilibili };if (onHost('xiaohongshu.com')) return { key: 'xiaohongshu', rules: SITE_INTERACTION_RULES.xiaohongshu };+ if (onHost('tieba.baidu.com')) return { key: 'baiduTieba', rules: SITE_INTERACTION_RULES.baiduTieba };// LinkedIn's interop shell renders major surfaces (the post composer// dialog among them) inside the open #interop-outlet shadow root. No// custom interaction rules needed — piercing alone makes the dialog'sdiff --git a/test/run.js b/test/run.jsindex ba059e962..459947a56 100644--- a/test/run.js+++ b/test/run.js@@ -4601,6 +4601,71 @@ test('matches Baidu search surfaces without hijacking other Baidu products', ()assert.equal(firefoxAdapter?.notes, adapter?.notes);});+test('matches Baidu Tieba and exposes custom post like controls', () => {+ const trustedUrls = [+ 'https://tieba.baidu.com/',+ 'https://tieba.baidu.com/f?kw=python',+ 'https://tieba.baidu.com/p/11007201094?mo_device=1',+ 'https://tieba.baidu.com/mo/q/forum?kw=Python&page=1',+ ];+ for (const url of trustedUrls) {+ assert.equal(getActiveAdapter(url)?.name, 'baidu-tieba');+ assert.equal(getActiveAdapterFx(url)?.name, 'baidu-tieba');+ }++ for (const url of [+ 'https://tieba.baidu.com.evil.example/p/11007201094',+ 'https://www.baidu.com/p/11007201094',+ 'https://example.com/?next=https://tieba.baidu.com/p/11007201094',+ ]) {+ assert.notEqual(getActiveAdapter(url)?.name, 'baidu-tieba');+ assert.notEqual(getActiveAdapterFx(url)?.name, 'baidu-tieba');+ }++ const adapter = getActiveAdapter('https://tieba.baidu.com/p/11007201094?mo_device=1');+ assert.match(adapter?.notes || '', /custom Vue action bar/);+ assert.match(adapter?.notes || '', /named "点赞" control/);+ assert.match(adapter?.notes || '', /百度安全验证/);+ assert.equal(getActiveAdapterFx('https://tieba.baidu.com/p/11007201094')?.notes, adapter?.notes);++ const axChrome = fs.readFileSync(path.join(ROOT, 'src/chrome/src/content/accessibility-tree.js'), 'utf8');+ const axFirefox = fs.readFileSync(path.join(ROOT, 'src/firefox/src/content/accessibility-tree.js'), 'utf8');+ assert.equal(axChrome, axFirefox, 'Tieba accessibility shims must remain byte-identical');+ const start = axChrome.indexOf('const SITE_INTERACTION_RULES = {');+ const end = axChrome.indexOf('\n\n function getRole(el) {', start);+ const location = { hostname: 'tieba.baidu.com' };+ const context = { window: {}, location };+ vm.runInNewContext(axChrome.slice(start, end), context);+ const api = context.window.__wbSiteInteractions;+ const likeSelector = '.pc-pb-first-floor-interactive .action-item:has(use[*|href="#agree_pb"])';+ const replyLikeSelector = '.pc-pb-comments-desc .zan-container-dark:has(use[*|href="#agree_comment"])';+ const fakeElement = (selector, text) => ({+ innerText: text,+ textContent: text,+ matches: candidate => candidate === selector,+ getAttribute: () => null,+ });+ assert.ok(api.selectors().includes(likeSelector));+ assert.ok(api.selectors().includes(replyLikeSelector));+ assert.equal(api.describe(fakeElement(likeSelector, '98')).name, '点赞 98');+ assert.equal(api.describe(fakeElement(replyLikeSelector, '21')).name, '赞 21');+ assert.equal(api.shouldPierceShadowRoots(), false);++ for (const [label, rel] of [+ ['chrome', 'src/chrome/src/content/content.js'],+ ['firefox', 'src/firefox/src/content/content.js'],+ ]) {+ const content = fs.readFileSync(path.join(ROOT, rel), 'utf8');+ assert.match(content, /\.\.\._siteInteractiveSelectors\(\)/, `${label}: Tieba selectors must reach content discovery`);+ assert.match(content, /if \(_isSiteInteractive\(node\)\) return true/, `${label}: Tieba controls must be interactive`);+ }++ const cdp = fs.readFileSync(path.join(ROOT, 'src/chrome/src/cdp/cdp-client.js'), 'utf8');+ assert.match(cdp, /onHost\('tieba\.baidu\.com'\)/);+ assert.match(cdp, /agree_pb/);+ assert.match(cdp, /agree_comment/);+});+test('matches twitter.com and x.com', () => {assert.equal(getActiveAdapter('https://twitter.com/elonmusk')?.name, 'twitter');assert.equal(getActiveAdapter('https://x.com/elonmusk')?.name, 'twitter');