import { chromium } from 'playwright'; async function run({ soldPrice, shippingCharged, itemCost, shippingCost, noOfOrders, ebayStore, sellerLevel, overseaSales, promotedRate, charityRate, salesTaxMethod, salesTaxAmount, salesTaxIncludesShipping, itemCategory, artSubcategory }) { const browser = await chromium.launch({ headless: true }); const page = await browser.newPage(); // Navigate to the page await page.goto('https://www.ebayfeescalculator.com/usa-ebay-calculator/'); // Fill in input fields await page.fill('#fieldname2_1', soldPrice); // Sold price await page.fill('#fieldname3_1', shippingCharged); // Shipping charged await page.fill('#fieldname4_1', itemCost); // Item cost await page.fill('#fieldname5_1', shippingCost); // Shipping cost await page.fill('#fieldname6_1', noOfOrders); // Number of orders // Select options await page.selectOption('#fieldname7_1', { value: ebayStore }); // eBay store await page.selectOption('#fieldname9_1', { value: sellerLevel }); // Seller level await page.selectOption('#fieldname10_1', { value: overseaSales }); // Oversea sales await page.fill('#fieldname13_1', promotedRate); // Promoted ad rate await page.fill('#fieldname48_1', charityRate); // Charity rate // Sales tax options await page.selectOption('#fieldname76_1', { value: salesTaxMethod }); // Sales tax method await page.fill('#fieldname56_1', salesTaxAmount); // Sales tax amount await page.selectOption('#fieldname57_1', { value: salesTaxIncludesShipping }); // Sales tax includes shipping // Category options await page.selectOption('#fieldname14_1', { value: itemCategory }); // Item category if (artSubcategory) { await page.selectOption('#fieldname80_1', { value: artSubcategory }); // Art subcategory } // Extract information by ID async function extractText(selector) { try { return await page.innerText(selector); } catch (error) { console.error(`Error extracting text from selector "${selector}":`, error); return null; } } const result1 = await extractText('#fieldname42_1'); const result2 = await extractText('#fieldname60_1 h3'); const result3 = await extractText('#fieldname43_1 h3'); const result4 = await extractText('#fieldname43_1 h4'); console.log(result1); console.log(result2); console.log(result3); console.log(result4); await browser.close(); } // Example usage run({ soldPrice: '{{$soldPrice}}', shippingCharged: '{{ $shippingCharged??1 }}', itemCost: '{{ $itemCost??'' }}', shippingCost: '{{ $shippingCost??'' }}', noOfOrders: '{{ $noOfOrders??'1' }}', ebayStore: '{{ $ebayStore??'Starter' }}', sellerLevel: '{{ $sellerLevel??'Top Rated' }}', overseaSales: '{{ $overseaSales??'No' }}', promotedRate: '{{ $promotedRate??'' }}', charityRate: '{{ $charityRate??'' }}', salesTaxMethod: '{{ $salesTaxMethod??'% Percentage' }}', salesTaxAmount: '{{ $salesTaxAmount??'' }}', salesTaxIncludesShipping: '{{ $salesTaxIncludesShipping??'Yes' }}', itemCategory: '{{ $itemCategory }}', artSubcategory: '{{ $artSubcategory??'' }}', amount: {{ $amount }} });