feat(jd,taobao,cnki): add JD, Taobao, and CNKI adapters#248
feat(jd,taobao,cnki): add JD, Taobao, and CNKI adapters#248jackwener merged 1 commit intojackwener:mainfrom
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Impressive scope — complete shopping workflows for both JD and Taobao, including spec selection. A few concerns, some more serious than others:
page.evaluate injection — user input interpolated into JS strings
Several adapters embed kwargs.sku / kwargs.id directly inside page.evaluate template strings without validation:
// jd/detail.ts
{ field: 'SKU', value: '${kwargs.sku}' }
// taobao/detail.ts
location.href = 'https://item.taobao.com/item.htm?id=${kwargs.id}'If the value contains a single quote or backtick, it breaks the script; a crafted value can inject arbitrary JS in the page's authenticated context. Since sku and id are always numeric, a simple guard like if (!/^\d+$/.test(kwargs.sku)) throw ... before interpolation would close this.
Affected files: jd/detail.ts, jd/add-cart.ts, taobao/detail.ts, taobao/reviews.ts, taobao/add-cart.ts, taobao/search.ts.
add-cart — write operations with no dry-run
Both jd/add-cart and taobao/add-cart modify real shopping carts on execution. taobao/add-cart also auto-selects the first available spec when --spec is omitted, which could surprise users. Consider adding a --dry-run flag that shows what would be added without committing the action.
taobao/reviews.ts — JSONP script injection
The JSONP callback creates a global window[cbName] and injects a <script> tag, but neither the script element nor the callback is reliably cleaned up on all paths (success, error, timeout). The 10s timeout and callback deletion can also race. Minor, but worth a cleanup pass.
Taobao two-step navigation
All 5 Taobao adapters do goto('https://www.taobao.com') → wait(2) → evaluate location.href = target. This is presumably to establish session cookies before navigating to item pages. A brief comment explaining the rationale would help future maintainers understand whether this can be simplified.
jd/cart.ts — hardcoded delivery region
The cart API URL includes area=22_1930_50948_52157, which locks prices/availability to a specific region. Worth documenting as a known limitation or making it configurable.
Tests
This is the second consecutive PR (after #243) with zero test coverage. 11 new commands — including 2 write operations — with no E2E entries. Per TESTING.md, browser+auth commands should have entries in browser-auth.test.ts (at minimum verifying graceful failure when not logged in). The add-cart commands especially need test coverage to ensure they don't silently "succeed" in unauthenticated sessions.
|
能否单独上传一个cnki的pr?我看他只回复你了jd和tb的请求 |
|
@W0rry628 谢谢测试! CNKI adapter 需要通过 opencli + Browser Bridge 扩展在 Chrome 里运行,不能直接在浏览器地址栏打开 URL。因为 CNKI 的搜索结果页是动态渲染的,需要完整的浏览器 JS 环境才能加载。 我刚测了 使用方式:
PR 描述里之前没写这个前置条件,已经补上了。 |
|
@Muuuun |
d8168fe to
fc5752b
Compare

Summary
Prerequisites
All commands in this PR are browser commands (
Strategy.COOKIE). They require:opencliin the terminal (not by opening URLs directly in the browser)JD (京东) — 5 commands
jd search <query>jd detail <sku>jd reviews <sku>jd add-cart <sku>cart.jd.com/gate.action(--dry-runsupported)jd cartJD uses fully obfuscated CSS classes — extraction uses
div[data-sku]attributes and text pattern matching.Taobao (淘宝) — 5 commands
taobao search <query>taobao detail <id>taobao reviews <id>taobao add-cart <id>--dry-runsupported)taobao cartTaobao uses obfuscated CSS with semantic prefixes (e.g.
title--xxx,priceInt--xxx,realSales--xxx). The adapter matches via[class*="prefix--"]selectors. Item IDs are extracted fromdata-spm-act-idattributes.Note: Taobao requires login in the automation window.
CNKI (知网) — 1 command
cnki search <query>oversea.cnki.netChanges since review
Addressed all feedback from @Astro-Han:
/^\d+$/validation forsku/idbefore interpolation intopage.evaluate; query length validation for search commands--dry-runfor add-cart — bothjd add-cartandtaobao add-cartnow support--dry-runto preview without modifying the carttaobao/reviews.tswith asettledguard andcleanup()to reliably remove callback + script element on all pathsgoto(taobao.com)→location.hrefis needed (session cookie establishment)jd/cart.tsAPIareaparameter documented as known limitation (北京)browser-auth.test.ts(5 JD + 5 Taobao + 1 CNKI + 1 CNKI graceful failure)Test plan
npx tsc --noEmit— type check passednpx vitest run src/— all 306 unit tests passedopencli validate— 86 CLI definitions validated, 0 errors🤖 Generated with Claude Code