feat: add detailed task logic to skip invalid ASINs.

This commit is contained in:
PetrichorFun 2026-01-27 18:01:17 +08:00
parent 4ec4d79457
commit 169be0e142
6 changed files with 34 additions and 2 deletions

View File

@ -63,8 +63,6 @@ export async function exec<T, P extends Record<string, unknown>>(
const tab = await browser.tabs.get(tabId);
if (tab.status !== 'complete') {
console.log('waitForPageLoaded');
await browser.tabs.reload(tabId);
await new Promise((resolve) => setTimeout(resolve, 2000)); // 等待刷新开始
}

View File

@ -140,6 +140,11 @@ function buildAmazonPageWorker(): WorkerComposable<AmazonPageWorker, AmazonPageW
worker.on('item-review-collected', (ev) => {
updateReviewCache(ev);
}),
// current tab is error page
// 处理无效ASIN事件
// worker.on('invalid-asin-error', (ev) => {
// updateDetailCache({ asin: ev.asin, isInvalidAsin: true });
// }),
];
return () => unsubscribes.forEach((unsubscribe) => unsubscribe());

View File

@ -129,6 +129,15 @@ class AmazonPageWorkerImpl
});
}
const injector = new AmazonDetailPageInjector(tab);
// check if it is an error page
await new Promise((resolve) => setTimeout(resolve, 2000)); // 等待页面加载
const isErrorPage = await injector.detectErrorPage();
if (isErrorPage) {
this.emit('invalid-asin-error', { asin: params.asin });
return; // 直接返回跳过该ASIN
}
//#endregion
//#region Await Production Introduction Element Loaded
await injector.waitForPageLoaded();

View File

@ -45,6 +45,9 @@ export interface AmazonPageWorkerEvents {
/** Error event that occurs when there is an issue with the Amazon page worker*/
['error']: { message: string; url?: string };
/** The event is fired when current tab is error page */
['invalid-asin-error']: { asin: string };
}
export interface AmazonPageWorker extends Listener<AmazonPageWorkerEvents> {

View File

@ -379,6 +379,14 @@ export class AmazonSearchPageInjector extends BaseInjector {
}
export class AmazonDetailPageInjector extends BaseInjector {
/**检测是否是错误页面 */
public async detectErrorPage(): Promise<boolean> {
return this.run(async () => {
const errorImage = document.querySelector('img[src*="error/en_US/title"]');
return !!errorImage;
});
}
/**等待页面加载完成 */
public async waitForPageLoaded() {
return this.run(async () => {

View File

@ -71,6 +71,15 @@ worker.on('item-extra-info-collect', (ev) => {
content: `获取商品的额外信息`,
});
});
worker.on('invalid-asin-error', (ev) => {
timelines.value.push({
type: 'warning',
title: `跳过无效ASIN`,
time: new Date().toLocaleString(),
content: `ASIN ${ev.asin} 页面无效,已跳过`,
});
});
//#endregion
const launch = async () => {