HTTPCloak Node.js Client

1.6.1 · active · verified Wed Apr 22

HTTPCloak is a Node.js HTTP client specifically engineered for advanced browser fingerprint emulation across HTTP/1.1, HTTP/2, and HTTP/3 (QUIC) protocols. It is designed to mimic real browser characteristics, including TLS and HTTP/2 fingerprints, to bypass sophisticated bot detection systems. The current stable version is 1.6.1, indicating an actively developed library that regularly incorporates updates necessary to counter evolving anti-bot technologies. While a formal release cadence isn't specified, libraries in this domain typically require frequent maintenance. Its key differentiators include comprehensive multi-protocol support and configurable browser presets, making it highly effective for web scraping, automation, and bypassing anti-bot measures.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates promise-based asynchronous usage of HTTPCloak, covering GET and POST requests, handling responses, and executing concurrent requests, while emphasizing proper session management with `session.close()`.

import { Session } from 'httpcloak';

async function runHttpcloakExample() {
  const session = new Session({
    preset: 'chrome-latest', // Emulate the latest Chrome browser fingerprint
    // You can also specify proxy, timeouts, etc. here
    // proxy: 'http://username:password@proxy.example.com:8080',
    // timeout: 15000
  });

  try {
    console.log('Performing GET request to Cloudflare trace...');
    const getResponse = await session.get('https://www.cloudflare.com/cdn-cgi/trace');
    console.log('GET Status Code:', getResponse.statusCode);
    console.log('GET Response Text:\n', getResponse.text.slice(0, 200), '...'); // Log first 200 chars

    console.log('\nPerforming POST request to a mock API...');
    const postResponse = await session.post('https://jsonplaceholder.typicode.com/posts', {
      title: 'foo',
      body: 'bar',
      userId: 1,
    }, {
      'Content-Type': 'application/json' // Custom headers for the request
    });
    console.log('POST Status Code:', postResponse.statusCode);
    console.log('POST Response JSON:', JSON.parse(postResponse.text));

    console.log('\nAttempting concurrent requests...');
    const [res1, res2] = await Promise.all([
      session.get('https://example.com/'),
      session.get('https://httpbin.org/get')
    ]);
    console.log('Concurrent Request 1 Status:', res1.statusCode);
    console.log('Concurrent Request 2 Status:', res2.statusCode);

  } catch (error) {
    console.error('An error occurred:', error.message);
  } finally {
    console.log('\nClosing HTTPCloak session...');
    session.close(); // Essential for resource cleanup
  }
}

runHttpcloakExample();

view raw JSON →