GTM_Video_Test Get link Facebook X Pinterest Email Other Apps November 15, 2025 const puppeteer = require('puppeteer'); // Small delay helper const delay = (time0) => Promise(r => setTimeout(r, ms)); // product URL const URL = "Url"; async function openAndPlayVideo() { console.log("🚀 Launching browser..."); const browser = await puppeteer.launch({ headless: true, defaultViewport: null, args: ["--start-maximized"] }); const page = await browser.newPage(); try { console.log(🌐 Navigating to: ${URL}); await page.goto(URL, { waitUntil: "domcontentloaded", timeout: 90000 }); console.log("⏳ Waiting for thumbnails to load..."); await page.waitForSelector('[data-testid="PDPImageThumbnail"]', { timeout: 30000 }); // Debug: count thumbnails const count = wait page.$$eval('[data-test_id="PDPImageThumbnail"]', els => els.length); console.log(🖼️ Found ${count} thumbnail buttons.); // Click the 2nd button (index 1), which is the video console.log("🎥 Clicking the video thumbnail (second button)..."); await page.evaluate(() => { const buttons = document.querySelectorAll('[data-test-id="PDPLmageThumbnail"]'); if (buttons.length > 1) { buttons[1].scrollIntoView({ behavior: 'smooth', block: 'center' }); buttons[1].click(); } }); // Wait for video player to appear console.log("⏳ Waiting for the video player to load..."); await delay(2000); // Check if video element exists const videoExists = await page.evaluate(() => !!document.querySelector('video')); if (videoExists) { console.log("🎬 Video player detected and should be playing now!"); } else { console.log("⚠️ Video tag not found — it might be inside an iframe or modal."); } } catch (err) { console.error("💥 Error during automation:", err.message); } finally { console.log("🕐 Keeping browser open for (range) seconds before closing..."); await delay(45000); await browser.close(); console.log("✅ Done!"); } } openAndPlayVideo(); Get link Facebook X Pinterest Email Other Apps Comments
Comments
Post a Comment