Warning

Zyte API is replacing Smart Proxy Manager. It is no longer possible to sign up to Smart Proxy Manager. If you are an existing Smart Proxy Manager user, see Migrating from Smart Proxy Manager to Zyte API.

Using Smart Proxy Manager with Playwright#

Warning

For the code below to work you must first install the Zyte CA certificate.

Note

Playwright requires Node.js and npm installed and an active Smart Proxy Manager account. Log in here.

Note

All the code in this documentation has been tested with Node.js v14.15.1 and playwright 1.15.0.

Option 1 - Plugin for Playwright-Extra#

Check out details here.

Option 2 - Zyte SmartProxy Playwright#

Installation#

Download and install Zyte SmartProxy Playwright:

$ npm install zyte-smartproxy-playwright

Sample script#

Zyte SmartProxy Playwright is a client library that provides Zyte Smart Proxy Manager related functionalities over Playwright.

  1. In order to run the sample code present below save it in a file named sample.js:

const { chromium } = require('zyte-smartproxy-playwright'); // Or 'firefox' or 'webkit'

(async () => {
    const browser = await chromium.launch({
        spm_apikey: '<Smart Proxy Manager API KEY>',
        headless: false,
    });
    console.log('Before new page');
    const page = await browser.newPage({ignoreHTTPSErrors: true});

    console.log('Opening page ...');
    try {
        await page.goto('https://toscrape.com/', {timeout: 180000});
    } catch(err) {
        console.log(err);
    }

    console.log('Taking a screenshot ...');
    await page.screenshot({path: 'screenshot.png'});
    await browser.close();
})();
  1. Now run the sample code using Node:

node sample.js

To know more about what you can do with Zyte SmartProxy Playwright, check out the API Documentation.

Option 3 - Zyte SmartProxy Headless Proxy#

Installation#

Setup the Zyte SmartProxy (formerly Crawlera) Headless Proxy as described in Using Headless Browsers with Zyte Smart Proxy Manager.

Download and install Playwright:

$ npm install playwright

Sample script#

Here is a sample script you can use to test the integration of Playwright with Smart Proxy Manager, once you have installed the Headless Proxy.

const playwright = require('playwright');

async function main() {
    var browserFirefox = await playwright.firefox.launch({
        proxy: {server: "localhost:3128"}
    });
    var url = "https://toscrape.com/"
    const page = await browserFirefox.newPage({ignoreHTTPSErrors: true});
    await page.goto(url);
    await page.screenshot({path: 'screenshot.png', fullPage: true});
    await browserFirefox.close();
};

main();