Files
cannaiq/backend/check-product-detail-page.ts
2025-11-28 19:45:44 -07:00

76 lines
2.6 KiB
TypeScript

import { firefox } from 'playwright';
import { getRandomProxy } from './src/utils/proxyManager.js';
async function checkProductDetailPage() {
const proxy = await getRandomProxy();
if (!proxy) {
console.log('No proxy available');
process.exit(1);
}
const browser = await firefox.launch({ headless: true });
const context = await browser.newContext({
viewport: { width: 1920, height: 1080 },
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
proxy: {
server: proxy.server,
username: proxy.username,
password: proxy.password
}
});
const page = await context.newPage();
// Load a product detail page
const productUrl = 'https://dutchie.com/embedded-menu/AZ-Deeply-Rooted/product/alien-labs-cured-resin-cart-dark-web';
console.log(`Loading: ${productUrl}`);
await page.goto(productUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.waitForTimeout(5000);
// Extract all data from the product detail page
const productData = await page.evaluate(() => {
const pageText = document.body.textContent || '';
// Check for prices
const priceElements = Array.from(document.querySelectorAll('*')).filter(el => {
const text = el.textContent?.trim() || '';
return text.match(/\$\d+/) && el.children.length === 0; // Leaf nodes only
});
// Check for stock information
const stockElements = Array.from(document.querySelectorAll('*')).filter(el => {
const text = el.textContent?.toLowerCase() || '';
return (text.includes('stock') || text.includes('available') || text.includes('in stock') || text.includes('out of stock')) && el.children.length === 0;
});
return {
hasPrice: pageText.includes('$'),
priceText: priceElements.slice(0, 5).map(el => el.textContent?.trim()),
stockText: stockElements.slice(0, 5).map(el => el.textContent?.trim()),
pageTextSample: pageText.substring(0, 500)
};
});
console.log('\n' + '='.repeat(80));
console.log('PRODUCT DETAIL PAGE DATA:');
console.log('='.repeat(80));
console.log('\nHas "$" symbol:', productData.hasPrice);
console.log('\nPrice elements found:');
productData.priceText.forEach((text, idx) => {
console.log(` ${idx + 1}. ${text}`);
});
console.log('\nStock elements found:');
productData.stockText.forEach((text, idx) => {
console.log(` ${idx + 1}. ${text}`);
});
console.log('\nPage text sample:');
console.log(productData.pageTextSample);
console.log('\n' + '='.repeat(80));
await browser.close();
process.exit(0);
}
checkProductDetailPage().catch(console.error);