Back to Blog

التحكم في Chrome Headless باستخدام Puppeteer و Proxy

بينما يعتبر Selenium أداة ممتازة، يفضل العديد من مطوري JavaScript استخدام Puppeteer للتحكم في متصفح Chrome. فهي أسرع، وتوفر تكاملاً أعمق مع أدوات التطوير (DevTools). في هذا المقال، سنشرح كيفية دمج البروكسي السكني مع Puppeteer.

إعداد البروكسي عند التشغيل

يتم تمرير إعدادات البروكسي عبر مصفوفة args عند إطلاق المتصفح.


const puppeteer = require('puppeteer');

(async () => {
    const proxy = '123.45.67.89:8080';
    
    const browser = await puppeteer.launch({
        headless: false,
        args: [
            `--proxy-server=${proxy}`,
            // تجاوز أخطاء شهادات HTTPS إذا لزم الأمر
            '--ignore-certificate-errors' 
        ]
    });

    const page = await browser.newPage();
    
    // التعامل مع المصادقة (Username/Password)
    await page.authenticate({
        username: 'myuser',
        password: 'mypassword'
    });

    await page.goto('https://whatismyipaddress.com');
    
    // أخذ لقطة شاشة للتأكد
    await page.screenshot({ path: 'proxy_test.png' });

    await browser.close();
})();
                    

تجنب الكشف (Anti-Detection)

مثل Selenium، المواقع قد تكتشف أنك تستخدم Puppeteer. يُنصح باستخدام مكتبة puppeteer-extra وإضافة puppeteer-extra-plugin-stealth لإخفاء بصمة الأتمتة.

تغيير البروكسي ديناميكياً

بشكل افتراضي، لا يدعم Puppeteer تغيير البروكسي للصفحة دون إعادة تشغيل المتصفح. إذا كنت بحاجة لتدوير البروكسي (Rotation) لكل طلب، يفضل استخدام خدمة Back-connect Proxy التي تقوم بالتدوير تلقائياً من جانب المزود، بحيث يبقى إعدادك ثابتاً ولكن الـ IP الخارجي يتغير.

Disclosure: we may earn a commission if you purchase through some links.

Services Related To This Article

These offers are related to privacy, password security, and development workflows. Replace the current links with your real affiliate links through environment variables.

Default Links Need Replacement

Proton

Privacy, mail, and VPN

A strong fit for privacy-focused visitors who want VPN and secure email under one brand.

Explore Proton

Surfshark

Consumer VPN

Best on pages about geo-blocking, privacy, and public Wi-Fi protection.

Try Surfshark

NordVPN

High-converting VPN

A clear offer for users who need a paid, more durable alternative to a free proxy.

View NordVPN

1Password

Password management

The best match for password, secrets, team access, and personal security pages.

Discover 1Password

DigitalOcean

Developer cloud hosting

A strong fit for proxy setup, server, and infrastructure content aimed at developers and small teams.

Start with DigitalOcean