{"record":{"id":"a76597470b2b8fd7","repo":"jackwener/OpenCLI","slug":"selector-a76597","errorCode":"SELECTOR","errorMessage":"Could not find element: window.lib.mtop","messagePattern":"Could not find element: window\\.lib\\.mtop","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/item.js","lineNumber":131,"sourceCode":"    navigateBefore: false,\n    browser: true,\n    args: [\n        { name: 'item_id', required: true, positional: true, help: '闲鱼商品 item_id' },\n    ],\n    columns: ['item_id', 'title', 'price', 'condition', 'brand', 'location', 'seller_name', 'want_count'],\n    func: async (page, kwargs) => {\n        const itemId = normalizeNumericId(kwargs.item_id, 'item_id', '1040754408976');\n        await page.goto(buildItemUrl(itemId));\n        await page.wait(2);\n        const result = await page.evaluate(buildFetchItemEvaluate(itemId));\n        if (result?.error === 'auth-required') {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu item detail requires a logged-in browser session');\n        }\n        if (result?.error === 'blocked') {\n            throw new EmptyResultError('xianyu item', 'Xianyu item detail is blocked by verification or risk control');\n        }\n        if (result?.error === 'mtop-not-ready') {\n            throw selectorError('window.lib.mtop', '闲鱼页面未完成初始化，无法调用商品详情接口');\n        }\n        if (!result || typeof result !== 'object') {\n            throw new EmptyResultError('xianyu item', '闲鱼商品详情接口未返回有效数据');\n        }\n        const errorCode = String(result.error_code || '');\n        const errorMessage = String(result.error_message || '');\n        if (/FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED|FAIL_SYS/.test(errorCode) || /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED/.test(errorMessage)) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu item detail requires a logged-in browser session');\n        }\n        if (result.error) {\n            throw new EmptyResultError('xianyu item', errorMessage || `Xianyu item detail request failed: ${result.error}`);\n        }\n        if (!String(result.title || '').trim()) {\n            throw new EmptyResultError('xianyu item', 'No item detail was returned for the specified item_id');\n        }\n        return [result];\n    },\n});","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/item.js#L113-L149","documentation":"selectorError thrown when the in-page mtop bridge (window.lib.mtop) is not available, reported by the evaluate as error 'mtop-not-ready'. The library maps that to 'element not found' because the page's API client object never initialized.","triggerScenarios":"Calling xianyu item detail (clis/xianyu/item.js) while the Goofish page has not finished booting its JS bundle, so window.lib.mtop is undefined and the mtop API call cannot be made.","commonSituations":"Slow network or heavy page still bootstrapping when the evaluate runs; page landed on an interstitial/version-rollback page; Goofish renamed/relocated window.lib.mtop.","solutions":["Increase the wait before evaluating so the page finishes initializing window.lib.mtop","Reload the item page and retry once initialization completes","Check for anti-bot interstitials that block bundle execution and solve them first","If Goofish changed its internals, update the evaluate to the new mtop access path"],"exampleFix":"// before\nconst r = await page.evaluate(fetchItemViaMtop(id));\n// after\nawait page.waitForFunction(() => window.lib && window.lib.mtop);\nconst r = await page.evaluate(fetchItemViaMtop(id));","handlingStrategy":"retry","validationCode":"await page.waitForFunction(() => window.lib && typeof window.lib.mtop === 'object', { timeout: 15000 });","typeGuard":"const mtopReady = () => page.evaluate(() => Boolean(window.lib && window.lib.mtop));","tryCatchPattern":"try {\n  await opencli xianyu item --id 123;\n} catch (e) {\n  if (e.code === 'SELECTOR' && e.message.includes('window.lib.mtop')) {\n    await page.reload();\n    await page.waitForFunction(() => window.lib && window.lib.mtop);\n    await opencli xianyu item --id 123;\n  } else throw e;\n}","preventionTips":["Wait for window.lib.mtop before evaluating mtop-dependent scripts","Allow generous timeouts on slow networks","Detect and solve anti-bot interstitials early","Track Goofish bundle changes that relocate the mtop global"],"tags":["selector","xianyu","page-initialization"],"backgroundTag":"selector-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}