fixed build libs
This commit is contained in:
parent
b03231b849
commit
42baadae38
26 changed files with 981 additions and 541 deletions
|
|
@ -9,7 +9,7 @@ export class SimpleBrowser {
|
|||
private contexts = new Map<string, any>();
|
||||
private logger: any;
|
||||
private initialized = false;
|
||||
private options: BrowserOptions = {
|
||||
private _options: BrowserOptions = {
|
||||
headless: true,
|
||||
timeout: 30000,
|
||||
blockResources: false,
|
||||
|
|
@ -55,7 +55,7 @@ export class SimpleBrowser {
|
|||
}
|
||||
|
||||
// Merge options
|
||||
this.options = { ...this.options, ...options };
|
||||
this._options = { ...this._options, ...options };
|
||||
|
||||
this.logger.info('Initializing browser...');
|
||||
|
||||
|
|
@ -91,8 +91,8 @@ export class SimpleBrowser {
|
|||
const page = await context.newPage();
|
||||
|
||||
// Add resource blocking if enabled
|
||||
if (this.options?.blockResources) {
|
||||
await page.route('**/*.{png,jpg,jpeg,gif,svg,ico,woff,woff2,ttf,css}', route => {
|
||||
if (this._options?.blockResources) {
|
||||
await page.route('**/*.{png,jpg,jpeg,gif,svg,ico,woff,woff2,ttf,css}', (route: any) => {
|
||||
route.abort();
|
||||
});
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ export class SimpleBrowser {
|
|||
|
||||
async goto(page: Page, url: string, options?: any): Promise<void> {
|
||||
await page.goto(url, {
|
||||
timeout: this.options?.timeout || 30000,
|
||||
timeout: this._options?.timeout || 30000,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
|
@ -143,6 +143,7 @@ export class SimpleBrowser {
|
|||
success: false,
|
||||
error: error.message,
|
||||
url,
|
||||
data: {} as any,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -163,12 +164,4 @@ export class SimpleBrowser {
|
|||
this.initialized = false;
|
||||
}
|
||||
|
||||
private get options(): BrowserOptions {
|
||||
return {
|
||||
headless: true,
|
||||
timeout: 30000,
|
||||
blockResources: false,
|
||||
enableNetworkLogging: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
||||
import { SimpleBrowser } from './simple-browser';
|
||||
import type { BrowserOptions } from './types';
|
||||
import { SimpleBrowser } from '../src/simple-browser';
|
||||
import type { BrowserOptions } from '../src/types';
|
||||
|
||||
describe('Browser', () => {
|
||||
let browser: SimpleBrowser;
|
||||
|
|
@ -1,14 +1,24 @@
|
|||
import type { ProxyInfo, ProxyConfig } from './types';
|
||||
import type { ProxyInfo } from './types';
|
||||
|
||||
export interface ProxyConfig {
|
||||
protocol: string;
|
||||
host: string;
|
||||
port: number;
|
||||
auth?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple proxy manager for testing
|
||||
*/
|
||||
export class SimpleProxyManager {
|
||||
private proxies: ProxyInfo[] = [];
|
||||
private proxies: Array<ProxyInfo & { id: string; active: boolean }> = [];
|
||||
private currentIndex = 0;
|
||||
private activeProxyIndex = 0;
|
||||
|
||||
addProxy(proxy: ProxyInfo): void {
|
||||
addProxy(proxy: ProxyInfo & { id: string; active: boolean }): void {
|
||||
this.proxies.push(proxy);
|
||||
}
|
||||
|
||||
|
|
@ -23,15 +33,15 @@ export class SimpleProxyManager {
|
|||
}
|
||||
}
|
||||
|
||||
getProxies(): ProxyInfo[] {
|
||||
getProxies(): Array<ProxyInfo & { id: string; active: boolean }> {
|
||||
return [...this.proxies];
|
||||
}
|
||||
|
||||
getActiveProxies(): ProxyInfo[] {
|
||||
getActiveProxies(): Array<ProxyInfo & { id: string; active: boolean }> {
|
||||
return this.proxies.filter(p => p.active);
|
||||
}
|
||||
|
||||
getNextProxy(): ProxyInfo | null {
|
||||
getNextProxy(): (ProxyInfo & { id: string; active: boolean }) | null {
|
||||
const activeProxies = this.getActiveProxies();
|
||||
if (activeProxies.length === 0) {
|
||||
return null;
|
||||
|
|
@ -39,10 +49,10 @@ export class SimpleProxyManager {
|
|||
|
||||
const proxy = activeProxies[this.activeProxyIndex % activeProxies.length];
|
||||
this.activeProxyIndex++;
|
||||
return proxy;
|
||||
return proxy || null;
|
||||
}
|
||||
|
||||
getProxyConfig(proxy: ProxyInfo): ProxyConfig {
|
||||
getProxyConfig(proxy: ProxyInfo & { id: string; active: boolean }): ProxyConfig {
|
||||
const config: ProxyConfig = {
|
||||
protocol: proxy.protocol,
|
||||
host: proxy.host,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
||||
import { SimpleProxyManager } from './simple-proxy-manager';
|
||||
import type { ProxyConfig, ProxyInfo } from './types';
|
||||
import { SimpleProxyManager } from '../src/simple-proxy-manager';
|
||||
import type { ProxyConfig, ProxyInfo } from '../src/types';
|
||||
|
||||
describe('ProxyManager', () => {
|
||||
let manager: SimpleProxyManager;
|
||||
Loading…
Add table
Add a link
Reference in a new issue