fix: use localhost for CDP (IPv6), prevent null overwrite on dimensions

- CDP discovery uses localhost instead of 127.0.0.1 (Chrome binds IPv6)
- Only overwrite logistics fields when parsing succeeds, preventing
  later unparseable keys from nullifying valid parsed values

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-03-30 12:08:41 +08:00
parent e48592690b
commit bff990628b
1 changed files with 5 additions and 5 deletions

View File

@ -81,7 +81,7 @@ class CdpSession {
private pending = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>(); private pending = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();
static async connect(port: number): Promise<CdpSession> { static async connect(port: number): Promise<CdpSession> {
const resp = await fetch(`http://127.0.0.1:${port}/json`); const resp = await fetch(`http://localhost:${port}/json`);
const targets = (await resp.json()) as Array<{ webSocketDebuggerUrl: string; type: string }>; const targets = (await resp.json()) as Array<{ webSocketDebuggerUrl: string; type: string }>;
const page = targets.find(t => t.type === 'page'); const page = targets.find(t => t.type === 'page');
if (!page) throw new Error('No Chrome page tab found. Open a tab first.'); if (!page) throw new Error('No Chrome page tab found. Open a tab first.');
@ -414,12 +414,12 @@ export async function run(
if (logistics.weight) logistics.weight.source = 'attributes'; if (logistics.weight) logistics.weight.source = 'attributes';
} }
if (matchKey(key, DIMENSION_KEYS)) { if (matchKey(key, DIMENSION_KEYS)) {
logistics.dimensions = parseDimensions(val); const parsed = parseDimensions(val);
if (logistics.dimensions) logistics.dimensions.source = 'attributes'; if (parsed) { parsed.source = 'attributes'; logistics.dimensions = parsed; }
} }
if (matchKey(key, VOLUME_KEYS)) { if (matchKey(key, VOLUME_KEYS)) {
logistics.volume = parseVolume(val); const parsed = parseVolume(val);
if (logistics.volume) logistics.volume.source = 'attributes'; if (parsed) { parsed.source = 'attributes'; logistics.volume = parsed; }
} }
if (matchKey(key, ['产地', '发货地', '所在地'])) { if (matchKey(key, ['产地', '发货地', '所在地'])) {
logistics.origin = val; logistics.origin = val;