Session/Login Extractor avatar
Session/Login Extractor

Pricing

Pay per usage

Go to Store
Session/Login Extractor

Session/Login Extractor

Developed by

pragmaticcoders

Maintained by Community

Automates login flows and extracts session data. Supports MFA with TOTP code. You can use this actor if you need to access website with authentication.

0.0 (0)

Pricing

Pay per usage

0

Total users

10

Monthly users

7

Runs succeeded

>99%

Last modified

a month ago

Session Extractor

🚀 Automates login flows and extracts session data

  • cookies (including httpOnly)
  • localStorage
  • sessionStorage

🔹 Features

  • Automates user actions (click, type, sleep, TOTP)
  • Extracts session data
  • 😍 Saves screenshots before interactions - makes debugging easier
  • Supports custom User-Agent & Apify Proxy
  • Smart element selection - handles multiple elements with index or position
  • Two-Factor Authentication - supports TOTP code generation

📥 Input Example

1{
2  "signInPageURL": "https://example.com/login",
3  "steps": [
4    { "action": "type", "selector": "#username", "value": "myUsername" },
5    { "action": "type", "selector": "#password", "value": "mySecurePassword" },
6    { "action": "click", "selector": "#login-button" },
7    { "action": "sleep", "value": 2000 },
8    { "action": "totp", "selector": "#totp-input", "pressEnter": true }
9  ],
10  "cookieDomains": ["example.com"],
11  "userAgent": "Mozilla/5.0 ...",
12  "totpSecret": "YOUR_TOTP_SECRET"
13}

Session data will be stored in the default key-value store under the name SESSION_DATA.
(storage name can be customized)

Input options:

1export interface InputSchema {
2  // URL of the sign-in page
3  signInPageURL: string;
4
5  // List of user actions to perform
6  steps: Step[];
7
8  // List of domains to extract cookies from
9  cookieDomains: string[];
10
11  // Timeout for each page navigation (default: 30)
12  gotoTimeout?: number;
13
14  // Custom proxy configuration
15  proxyConfiguration?: ProxyConfig;
16
17  // Whether to use Apify Proxy
18  forceCloud?: boolean;
19
20  // Custom User-Agent
21  userAgent?: string;
22
23  // Whether to run in headless mode (default: false)
24  headless?: boolean;
25  
26  // Custom storage name (default: 'SESSION_DATA')
27  storageName?: string;
28
29  // Secret key for TOTP code generation
30  totpSecret?: string;
31}
1export interface Step {
2  // Action to perform: 'click', 'type', 'sleep', or 'totp'
3  action: 'click' | 'type' | 'sleep' | 'totp';
4
5  // CSS selector for the element
6  selector?: string;
7
8  // Value to type or sleep duration in milliseconds
9  value?: string | number;
10  
11  // Element index if multiple elements are found
12  // Can be a number, 'first', or 'last'
13  eq?: 'first' | 'last' | number;
14  
15  // Whether element should be visible (default: true)
16  visible?: boolean;
17  
18  // Press enter after typing value (default: false)
19  pressEnter?: boolean;
20  
21  // Wait for navigation after step (default: false)
22  waitForNavigation?: boolean;
23
24  // Whether the step is optional (won't fail if element not found)
25  optional?: boolean;
26}
1export interface ProxyConfig {
2  useApifyProxy?: boolean;
3  apifyProxyGroups?: string[];
4}

🔍 Action Examples

Click Action

1// Simple click
2{ "action": "click", "selector": "#submit-button" }
3
4// Click second element when multiple matches exist
5{ "action": "click", "selector": ".login-button", "eq": 1 }
6
7// Click last element in a list
8{ "action": "click", "selector": ".pagination-item", "eq": "last" }
9
10// Click and wait for navigation
11{ "action": "click", "selector": "#submit", "waitForNavigation": true }
12
13// Optional click (won't fail if element not found)
14{ "action": "click", "selector": "#cookie-banner", "optional": true }

Type Action

1// Simple typing
2{ "action": "type", "selector": "#username", "value": "user@example.com" }
3
4// Type and press Enter
5{ "action": "type", "selector": "#password", "value": "password123", "pressEnter": true }
6
7// Type into a specific input when multiple exist
8{ "action": "type", "selector": ".input-field", "eq": "first", "value": "test" }
9
10// Optional type (won't fail if element not found)
11{ "action": "type", "selector": "#optional-field", "value": "test", "optional": true }
12
13// Type and wait for navigation (useful for forms)
14{ "action": "type", "selector": "#search", "value": "query", "pressEnter": true, "waitForNavigation": true }

Sleep Action

1// Wait for 2 seconds
2{ "action": "sleep", "value": 2000 }
3
4// Wait for 5 seconds (e.g., for animations or loading)
5{ "action": "sleep", "value": 5000 }

TOTP Action

1// Generate and enter TOTP code
2{ "action": "totp", "selector": "#totp-input" }
3
4// Generate TOTP code, enter it, and press Enter
5{ "action": "totp", "selector": "#totp-input", "pressEnter": true }
6
7// Generate TOTP code and wait for navigation after submission
8{ "action": "totp", "selector": "#totp-input", "pressEnter": true, "waitForNavigation": true }

📸 Screenshots

The actor automatically takes screenshots before each interaction, making it easier to debug issues. Screenshots are saved with timestamps in the key-value store:

screenshot_1234567890.png

🔐 Session Data Example

The extracted session data will look like this:

1{
2  "cookies": {
3    "example.com": [
4      {
5        "name": "sessionId",
6        "value": "abc123",
7        "domain": "example.com",
8        "path": "/",
9        "expires": 1234567890,
10        "httpOnly": true,
11        "secure": true
12      }
13    ]
14  },
15  "localStorage": {
16    "theme": "dark",
17    "user": "{\"id\":123,\"name\":\"John\"}"
18  },
19  "sessionStorage": {
20    "lastPage": "/dashboard"
21  }
22}

🚀 Advanced Usage

Multi-Step Authentication

1{
2  "signInPageURL": "https://example.com/login",
3  "steps": [
4    { "action": "type", "selector": "#username", "value": "user@example.com" },
5    { "action": "type", "selector": "#password", "value": "password123", "pressEnter": true },
6    { "action": "sleep", "value": 2000 },
7    { "action": "totp", "selector": "#totp-input", "pressEnter": true, "waitForNavigation": true }
8  ],
9  "cookieDomains": ["example.com"],
10  "totpSecret": "YOUR_TOTP_SECRET"
11}

Multiple Domain Session Extraction

1{
2  "signInPageURL": "https://app.example.com/login",
3  "steps": [
4    { "action": "type", "selector": "#email", "value": "user@example.com" },
5    { "action": "type", "selector": "#password", "value": "password123" },
6    { "action": "click", "selector": "#submit" }
7  ],
8  "cookieDomains": [
9    "app.example.com",
10    "api.example.com",
11    "auth.example.com"
12  ]
13}

Custom Element Selection

1{
2  "steps": [
3    // Select first matching element
4    { "action": "click", "selector": ".login-option", "eq": "first" },
5    
6    // Select last matching element
7    { "action": "click", "selector": ".consent-button", "eq": "last" },
8    
9    // Select element by index (0-based)
10    { "action": "type", "selector": ".input-field", "eq": 2, "value": "test" }
11  ]
12}

Optional Steps Example

1{
2  "signInPageURL": "https://example.com/login",
3  "steps": [
4    // Handle cookie consent popup if present
5    { "action": "click", "selector": "#accept-cookies", "optional": true },
6    
7    // Close promotional overlay if it appears
8    { "action": "click", "selector": ".promo-close-button", "optional": true },
9    
10    // Proceed with normal login flow
11    { "action": "type", "selector": "#email", "value": "user@example.com" },
12    { "action": "type", "selector": "#password", "value": "password123" },
13    
14    // Some sites have an optional 2FA reminder skip button
15    { "action": "click", "selector": "#skip-2fa-setup", "optional": true },
16    
17    { "action": "click", "selector": "#login-button", "waitForNavigation": true }
18  ],
19  "cookieDomains": ["example.com"]
20}