# zyte-smartproxy-puppeteer-core

> A puppeteer-core enhancement with zyte smart proxy manager services.

Latest version **1.0.6** (published 2022-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install zyte-smartproxy-puppeteer-core
pnpm add zyte-smartproxy-puppeteer-core
yarn add zyte-smartproxy-puppeteer-core
bun add zyte-smartproxy-puppeteer-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-11-02 |
| First published | 2022-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zyte Group Ltd. |
| Maintainers | geronsv, gallaecio, storymode7 |
| Keywords | puppeteer, zyte, smart, proxy, manager |

## Links

- npm: https://www.npmjs.com/package/zyte-smartproxy-puppeteer-core
- Homepage: https://github.com/zytedata/zyte-smartproxy-puppeteer-core
- npm.io page: https://npm.io/package/zyte-smartproxy-puppeteer-core

## Dependencies (3)

- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.1.4
- [puppeteer-core](https://npm.io/package/puppeteer-core.md) ^10.4.0
- [@cliqz/adblocker-puppeteer](https://npm.io/package/@cliqz/adblocker-puppeteer.md) ^1.23.0

## Alternatives

- [@snazzah/davey](https://npm.io/package/@snazzah/davey.md) — 1.5M weekly downloads
- [@vendure/testing](https://npm.io/package/@vendure/testing.md) — 8.3K weekly downloads
- [vue-simple-context-menu](https://npm.io/package/vue-simple-context-menu.md) — 6.6K weekly downloads
- [cypress-webpack-preprocessor-v5](https://npm.io/package/cypress-webpack-preprocessor-v5.md) — 2.1K weekly downloads
- [@backstage/plugin-catalog-backend-module-puppetdb](https://npm.io/package/@backstage/plugin-catalog-backend-module-puppetdb.md) — 1.3K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2022-11-02
- 1.0.5 — 2022-10-14
- 1.0.4 — 2022-10-05
- 1.0.3 — 2022-10-05
- 1.0.2 — 2022-06-21
- 1.0.1 — 2022-05-16
- 1.0.0 — 2022-04-29

## README

# Zyte SmartProxy Puppeteer-Core
[![made-with-javascript](https://img.shields.io/badge/Made%20with-JavaScript-1f425f.svg)](https://www.javascript.com)
[![npm](https://img.shields.io/npm/v/zyte-smartproxy-puppeteer-core)](https://www.npmjs.com/package/zyte-smartproxy-puppeteer-core)

Use [puppeteer-core](https://github.com/puppeteer/puppeteer/) with
[Smart Proxy Manager](https://www.zyte.com/smart-proxy-manager/) easily!

A wrapper over puppeteer-core to provide Zyte Smart Proxy Manager specific functionalities.

## QuickStart

1. **Install Zyte SmartProxy puppeteer-core**

```
npm install zyte-smartproxy-puppeteer-core chrome-launcher axios
```

2. **Create a file `sample.js` with following content and replace `<SPM_APIKEY>` with your SPM Apikey**

``` javascript
const puppeteer = require('zyte-smartproxy-puppeteer-core');
const chromeLauncher = require('chrome-launcher');
const axios = require('axios');

(async () => {
    // Initializing a Chrome instance manually
    const chrome = await chromeLauncher.launch(
         {chromeFlags: ['--proxy-server=http://proxy.zyte.com:8011', '--disable-site-isolation-trials']}
    );
    const response = await axios.get(`http://localhost:${chrome.port}/json/version`);
    const { webSocketDebuggerUrl } = response.data;

    // Connect to the Chrome instance
    const browser = await puppeteer.connect({
        spm_apikey: '<SPM_APIKEY>',
        spm_host: 'http://proxy.zyte.com:8011',
        ignoreHTTPSErrors: true,
        browserWSEndpoint: webSocketDebuggerUrl,
        static_bypass: false, //  enable to save bandwidth (but may break some websites)
        block_ads: false, //  enable to save bandwidth (but may break some websites)
    });
    console.log('Before new page');
    const page = await browser.newPage();

    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();
})();
```

Make sure that you're able to make `https` requests using Smart Proxy Manager by following this guide [Fetching HTTPS pages with Zyte Smart Proxy Manager](https://docs.zyte.com/smart-proxy-manager/next-steps/fetching-https-pages-with-smart-proxy.html)

3. **Run `sample.js` using Node**

``` bash
node sample.js
```

## API

`ZyteProxyPuppeteer.connect` accepts all the arguments accepted by `Puppeteer.connect` and some
additional arguments defined below:

| Argument | Default Value | Description |
|----------|---------------|-------------|
| `spm_apikey` | `undefined` | Zyte Smart Proxy Manager API key that can be found on your zyte.com account. |
| `spm_host` | `http://proxy.zyte.com:8011` | Zyte Smart Proxy Manager proxy host. |
| `static_bypass` | `true` | When `true` ZyteProxyPuppeteer will skip proxy use for static assets defined by `static_bypass_regex` or pass `false` to use proxy. |
| `static_bypass_regex` | `/.*?\.(?:txt\|json\|css\|less\|gif\|ico\|jpe?g\|svg\|png\|webp\|mkv\|mp4\|mpe?g\|webm\|eot\|ttf\|woff2?)$/` | Regex to use filtering URLs for `static_bypass`. |
| `block_ads` | `true` | When `true` ZyteProxyPuppeteer will block ads defined by `block_list` using `@cliqz/adblocker-puppeteer` package. |
| `block_list` | `['https://secure.fanboy.co.nz/easylist.txt', 'https://secure.fanboy.co.nz/easyprivacy.txt']` | Block list to be used by ZyteProxyPuppeteer in order to initiate blocker enginer using `@cliqz/adblocker-puppeteer` and block ads |
| `headers` | `{'X-Crawlera-No-Bancheck': '1', 'X-Crawlera-Profile': 'pass', 'X-Crawlera-Cookies': 'disable'}` | List of headers to be appended to requests |

## Notes
- Some websites may not work with `block_ads` and `static_bypass` enabled (default). Try to disable them if you encounter any issues.

- When using remote browser in `headless` mode, values generated for some browser-specific headers are a bit different, which may be detected by websites. Try using ['X-Crawlera-Profile': 'desktop'](https://docs.zyte.com/smart-proxy-manager.html#x-crawlera-profile) in that case:
``` javascript
    const browser = await puppeteer.connect({
        spm_apikey: '<SPM_APIKEY>',
        spm_host: 'http://proxy.zyte.com:8011',
        ignoreHTTPSErrors: true,
        browserWSEndpoint: webSocketDebuggerUrl,
        headers: {'X-Crawlera-No-Bancheck': '1', 'X-Crawlera-Profile': 'desktop', 'X-Crawlera-Cookies': 'disable'}
    });
```

- Consider our new [zyte-smartproxy-plugin](https://github.com/zytedata/zyte-smartproxy-plugin) for [playwright-extra](https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra) 
and [puppeteer-extra](https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra) frameworks.

---
_Source: https://npm.io/package/zyte-smartproxy-puppeteer-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
