feat: extract window.context.result.data for structured logistics data
register-skill-release / register (push) Successful in 13s Details

Poll window.context.result.data (up to 15s) for productPackInfo,
productTitle, productAttributes, and skuSelection. This provides
structured weight/size/volume data per-variant directly from 1688's
JS context — more reliable than vision-only extraction.

Screenshots still captured as fallback for data only in images.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-03-30 14:05:53 +08:00
parent 93517505d4
commit 935cac3c61
1 changed files with 35 additions and 2 deletions

View File

@ -9,6 +9,8 @@ export interface ScrapeResult {
command: Command;
dryRun: boolean;
offerId: string;
productPackInfo?: unknown;
windowContext?: unknown;
screenshots?: string[];
detailImages?: string[];
error?: string;
@ -202,8 +204,37 @@ export async function run(
await cdp.send('Page.navigate', { url });
// Wait for page load + dynamic content
await new Promise(r => setTimeout(r, 5000));
// Wait for window.context.result.data to be populated (poll up to 15s)
let productPackInfo: unknown = null;
let windowContext: unknown = null;
for (let i = 0; i < 30; i++) {
await new Promise(r => setTimeout(r, 500));
const ctx = await cdp.evaluate(`
(function() {
try {
const d = window.context && window.context.result && window.context.result.data;
if (d && d.productPackInfo) {
return JSON.stringify({
productPackInfo: d.productPackInfo,
productTitle: d.productTitle || null,
productAttributes: d.productAttributes || null,
skuSelection: d.skuSelection || null,
});
}
} catch(e) {}
return null;
})()
`);
if (ctx) {
const parsed = JSON.parse(ctx);
productPackInfo = parsed.productPackInfo;
windowContext = parsed;
break;
}
}
// Extra wait for remaining dynamic content (images etc)
await new Promise(r => setTimeout(r, 2000));
const outputDir = path.join('/tmp', '1688-logistics', offerId);
@ -217,6 +248,8 @@ export async function run(
return {
status: 'success', url, command, dryRun, offerId,
productPackInfo,
windowContext,
screenshots,
detailImages,
};