Skip to content

Real-world Examples: Auto Login & Cookie Injection

This chapter provides a business template that you can directly apply: how to log into a website automatically and inject existing Cookies.

1. Automatic Login Template

javascript
// ... Configuration omitted
await page.goto('https://example.com/login');
await page.type('#email', 'test@example.com');
await page.type('#password', 'password123');
await page.click('#btn-submit');
await page.waitForNavigation(); // Wait for login to complete and the page to jump
console.log('Login successful!');

If you already have a user's Cookie, you can set it directly to enter the login state.

javascript
const cookies = [{ name: 'token', value: 'secret_value', domain: 'example.com' }];
await page.setCookie(...cookies);
await page.goto('https://example.com/dashboard');

3. High-Efficiency Positioning Tip: Using unique Mbbrowser fingerprints

When performing automation across multiple accounts, utilizing Mbbrowser's independent Cookie and LocalStorage features is key. Since each environment is isolated, you don't need to clear its state manually—each script starts with the environment's unique, persisted login state.


TIP

Mastered the basics? You can now build more complex automation systems based on your business needs.