A TypeScript HTTP client library with browser impersonation capabilities for Node.js.
- Browser Impersonation: Mimic Chrome, Safari, Edge, Firefox, and OkHttp across different operating systems
- TypeScript Support: Full TypeScript definitions and type safety
- Promise-based API: Modern async/await support
- Comprehensive HTTP Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
- Authentication: Support for Basic Auth and Bearer tokens
- SSL/TLS: Configurable SSL options including custom certificates
- Cookies: Automatic cookie handling
- Timeouts: Configurable request timeouts
- Error Handling: Robust error handling with custom error types
npm install trimpts
import { AsyncClient } from 'trimpts';
// Create a client with browser impersonation
const client = new AsyncClient({
impersonate: 'chrome',
impersonate_os: 'windows'
});
// Make a simple GET request
const response = await client.get('https://api.example.com/users');
console.log(response.json());
Promise-based HTTP client with async/await support.
const client = new AsyncClient(options);
Callback-based HTTP client.
const client = new Client(options);
interface ClientOptions {
timeout?: number; // Request timeout in milliseconds
headers?: Record<string, string>; // Custom headers
auth?: {
username?: string;
password?: string;
token?: string;
};
proxy?: {
host: string;
port: number;
auth?: {
username: string;
password: string;
};
};
cookies?: string; // Cookie string
ssl?: {
rejectUnauthorized?: boolean;
ca?: string;
cert?: string;
key?: string;
};
userAgent?: string; // Custom User-Agent
impersonate?: 'chrome' | 'safari' | 'edge' | 'firefox' | 'okhttp';
impersonate_os?: 'android' | 'ios' | 'linux' | 'macos' | 'windows';
}
All clients support the following methods:
get(url, options?)
- GET requestpost(url, data?, options?)
- POST requestput(url, data?, options?)
- PUT requestpatch(url, data?, options?)
- PATCH requestdelete(url, options?)
- DELETE requesthead(url, options?)
- HEAD requestoptions(url, options?)
- OPTIONS request
interface Response {
status: number;
headers: Record<string, string | string[] | undefined>;
data: string;
json<T = any>(): T; // Parse JSON response
text(): string; // Get text response
}
RequestError
- General request errorsTimeoutError
- Request timeout errors
TrimpTS can impersonate various browsers and operating systems:
// Chrome on Windows
const client = new AsyncClient({
impersonate: 'chrome',
impersonate_os: 'windows'
});
// Safari on macOS
const client = new AsyncClient({
impersonate: 'safari',
impersonate_os: 'macos'
});
// Firefox on Linux
const client = new AsyncClient({
impersonate: 'firefox',
impersonate_os: 'linux'
});
const client = new AsyncClient({
auth: {
username: 'user',
password: 'pass'
}
});
const client = new AsyncClient({
auth: {
token: 'your-jwt-token'
}
});
const response = await client.get('https://api.example.com/data', {
headers: {
'X-API-Key': 'your-api-key'
},
timeout: 10000
});
const response = await client.post('https://api.example.com/users', {
name: 'John Doe',
email: 'john@example.com'
});
const client = new AsyncClient({
ssl: {
rejectUnauthorized: false, // For self-signed certificates
ca: fs.readFileSync('ca.pem'),
cert: fs.readFileSync('cert.pem'),
key: fs.readFileSync('key.pem')
}
});
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see the LICENSE file for details.