Skip to content

fv pro detect antidetect browser #50

@nhamhuynh79

Description

@nhamhuynh79

what 's wrong code ?
const { plugin } = require('playwright-with-fingerprints');
const path = require('path');
const fs = require('fs');

async function main() {
const profileId = process.argv[2] || 'default_profile';
const dataOption = process.argv[3] || '1';
const employmentDataDir = process.argv[4] || './employment_data';

console.log(`Starting browser with profile: ${profileId}`);

try {
    // Set the service key (empty string for free version)
    plugin.setServiceKey(process.env.FINGERPRINT_API_KEY || 'key');

    // Set up user data directory
    const userDataDir = path.join(employmentDataDir, profileId);
    if (!fs.existsSync(userDataDir)) {
        fs.mkdirSync(userDataDir, { recursive: true });
    }

    // Fingerprint file path
    const fingerprintFile = path.join(userDataDir, 'fingerprint.json');
    
    let fingerprint;
    
    // Check if fingerprint already exists for this profile
    if (fs.existsSync(fingerprintFile)) {
        console.log('Loading existing fingerprint for profile:', profileId);
        fingerprint = fs.readFileSync(fingerprintFile, 'utf8');
        console.log('Existing fingerprint loaded successfully');
    } else {
        console.log('Getting new fingerprint for profile:', profileId);
        // Get fingerprint from the service
        fingerprint = await plugin.fetch({
             tags: ['Microsoft Windows', 'Chrome'], minBrowserVersion: 137, timeLimit: '45 days'
        });
        
        // Save fingerprint to file for future use
        fs.writeFileSync(fingerprintFile, fingerprint);
        console.log('New fingerprint acquired and saved');
    }

plugin.useFingerprint(fingerprint);
// Apply fingerprint
plugin.useFingerprint(fingerprint);

    // Use profile method to ensure all data is loaded/saved
    plugin.useProfile(userDataDir, {
        loadFingerprint: false, // We're setting fingerprint manually
        loadProxy: true         // Load proxy if exists in profile
    });

    // Launch browser with fingerprint and persistent context
    // Note: plugin.launch() returns a persistent context, not a browser
    const context = await plugin.launchPersistentContext(userDataDir, {
        headless: false,
        // Additional options to preserve all data
        acceptDownloads: true,
        args: [
            '--disable-restore-session-state',
        ]
    });

    console.log('Browser launched successfully');
    console.log('Profile directory:', userDataDir);
    console.log('All data (cookies, sessions, cache, history) will be preserved');

    // Create a new page
    const page = await context.newPage();

    console.log('Page created - you can now browse normally');
    console.log('Data persistence includes:');
    console.log('- Cookies and session data');
    console.log('- Browser history');
    console.log('- Cache files');
    console.log('- Local storage');
    console.log('- IndexedDB');
    console.log('- WebSQL');
    console.log('- Service worker data');
    console.log('Press Ctrl+C to close the browser');

    // Navigate to a test page to verify fingerprint
    await page.goto('https://bot.sannysoft.com/');

    // Keep the browser open
    await new Promise((resolve) => {
        process.on('SIGINT', async () => {
            console.log('\nClosing browser...');
            await context.close();
            resolve();
        });
    });

} catch (error) {
    console.error('Error:', error.message);
    process.exit(1);
}

}

main();
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions