115 lines
3.4 KiB
TypeScript
115 lines
3.4 KiB
TypeScript
/**
|
|
* Helper script to inspect a single Amazon order page
|
|
* Usage: bun inspect-order.ts <order-id>
|
|
*/
|
|
|
|
import puppeteer from 'puppeteer';
|
|
|
|
const orderId = process.argv[2] || '112-4052475-6569056';
|
|
|
|
console.log(`Inspecting order: ${orderId}`);
|
|
|
|
const browser = await puppeteer.launch({
|
|
headless: false,
|
|
userDataDir: './.puppeteer_cache',
|
|
args: ['--window-size=1920,1080'],
|
|
});
|
|
|
|
try {
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: 1920, height: 1080 });
|
|
|
|
// Navigate to order details page
|
|
const orderUrl = `https://www.amazon.com/gp/your-account/order-details?orderID=${orderId}`;
|
|
console.log(`Navigating to: ${orderUrl}`);
|
|
|
|
await page.goto(orderUrl, {
|
|
waitUntil: 'domcontentloaded',
|
|
timeout: 30000,
|
|
});
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
|
|
// Save debug files
|
|
await page.screenshot({ path: `debug-order-${orderId}.png`, fullPage: true });
|
|
const html = await page.content();
|
|
await Bun.write(`debug-order-${orderId}.html`, html);
|
|
console.log(`\nDebug files saved: debug-order-${orderId}.{png,html}`);
|
|
|
|
// Analyze the page structure
|
|
const analysis = await page.evaluate(() => {
|
|
// Look for all class names that might be relevant
|
|
const allElements = document.querySelectorAll('*');
|
|
const classNames = new Set<string>();
|
|
const dataTestIds = new Set<string>();
|
|
|
|
allElements.forEach(elem => {
|
|
if (elem.className && typeof elem.className === 'string') {
|
|
elem.className.split(' ').forEach(cls => {
|
|
if (cls.toLowerCase().includes('product') ||
|
|
cls.toLowerCase().includes('item') ||
|
|
cls.toLowerCase().includes('shipment') ||
|
|
cls.toLowerCase().includes('order')) {
|
|
classNames.add(cls);
|
|
}
|
|
});
|
|
}
|
|
|
|
const testId = elem.getAttribute('data-testid');
|
|
if (testId) {
|
|
dataTestIds.add(testId);
|
|
}
|
|
});
|
|
|
|
// Try to find product-related elements
|
|
const productSelectors = [
|
|
'.shipment .product',
|
|
'.a-box-group .a-fixed-left-grid',
|
|
'[data-asin]',
|
|
'.product-title',
|
|
'.a-link-normal',
|
|
'.a-size-medium',
|
|
'.yohtmlc-product-title',
|
|
'.yohtmlc-item',
|
|
];
|
|
|
|
const foundElements: any = {};
|
|
productSelectors.forEach(selector => {
|
|
const elements = document.querySelectorAll(selector);
|
|
if (elements.length > 0) {
|
|
foundElements[selector] = {
|
|
count: elements.length,
|
|
samples: Array.from(elements).slice(0, 3).map(el => ({
|
|
tag: el.tagName,
|
|
text: el.textContent?.trim().substring(0, 100),
|
|
classes: el.className,
|
|
}))
|
|
};
|
|
}
|
|
});
|
|
|
|
return {
|
|
classNames: Array.from(classNames).sort(),
|
|
dataTestIds: Array.from(dataTestIds).sort(),
|
|
foundElements,
|
|
pageTitle: document.title,
|
|
};
|
|
});
|
|
|
|
console.log('\n=== Page Analysis ===');
|
|
console.log('Page title:', analysis.pageTitle);
|
|
console.log('\nRelevant class names:', analysis.classNames.length);
|
|
console.log(analysis.classNames.slice(0, 20));
|
|
console.log('\nData-testid attributes:', analysis.dataTestIds.length);
|
|
console.log(analysis.dataTestIds.slice(0, 10));
|
|
console.log('\n=== Elements Found ===');
|
|
console.log(JSON.stringify(analysis.foundElements, null, 2));
|
|
|
|
console.log('\n\nPress Ctrl+C to close the browser and exit');
|
|
await new Promise(() => {}); // Keep browser open
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
} finally {
|
|
await browser.close();
|
|
}
|