{"id":17458153,"url":"https://github.com/pocesar/apify-login-session","last_synced_at":"2025-10-13T04:34:36.493Z","repository":{"id":40927815,"uuid":"237547456","full_name":"pocesar/apify-login-session","owner":"pocesar","description":"Grab a session for any website for usage on your own actor","archived":false,"fork":false,"pushed_at":"2024-06-19T21:02:11.000Z","size":447,"stargazers_count":10,"open_issues_count":12,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-18T06:28:40.081Z","etag":null,"topics":["actors","apify","apify-sdk","automation","cookies","form","localstorage","login","puppeteer","sessionstorage"],"latest_commit_sha":null,"homepage":"https://apify.com/pocesar/login-session","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pocesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-01T01:59:04.000Z","updated_at":"2024-06-01T06:59:18.000Z","dependencies_parsed_at":"2024-10-20T19:23:18.532Z","dependency_job_id":null,"html_url":"https://github.com/pocesar/apify-login-session","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fapify-login-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fapify-login-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fapify-login-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fapify-login-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pocesar","download_url":"https://codeload.github.com/pocesar/apify-login-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244734070,"owners_count":20501014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actors","apify","apify-sdk","automation","cookies","form","localstorage","login","puppeteer","sessionstorage"],"created_at":"2024-10-18T03:55:36.316Z","updated_at":"2025-10-13T04:34:31.447Z","avatar_url":"https://github.com/pocesar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Login Session\n\nGet localStorage, sessionStorage and cookies from logins for usage in other actors.\n\n## Usage\n\nThis actor can help you (re)use logged in sessions for your website and serivces, abstracting away the need for developing your own login mechanism. It uses a named session storage, so you when you request a new session, it will be readily available. It's tailored to work seamlessly on Apify platform and other actors.\n\nIt's more low-level than other actors, but it tries to cover the most common use cases like:\n\n* Single Page Applications\n* Server Side Rendered websites\n* Ajax login calls\n* Multi step logins such as username on one page, password on another\n\nYou may call directly from your actor, or use the `INPUT.json` to create a task or scheduled to keep seeding your session storage with new sessions. It cannot deal with 2FA or captchas (yet).\n\n```js\n// in your actor\nconst storageName = 'session-example';\n\nconst call = await Apify.call('pocesar/login-session', {\n    username: 'username',\n    password: 'password',\n    website: [{ url: 'http://example.com' }], // the RequestList format\n    cookieDomains: [\n        \"http://example.com\"\n    ],\n    sessionConfig: {\n        storageName,\n        maxAgeSecs: 3600,\n        maxUsageCount: 10,\n        maxPoolSize: 120\n    },\n    steps: [{\n        username: {\n            selector: \"input#email\", // the input that receives the username\n            timeoutMillis: 10000 // optional timeout in ms\n        },\n        password: {\n            selector: \"input#password\" // the input that receives the password\n        },\n        submit: {\n            selector: \"input[type=\\\"submit\\\"]\", // the button that executes the login\n        },\n        failed: {\n            selector: \"[role=\\\"alert\\\"],#captcha\", // usually an error that tells the login failed\n            timeoutMillis: 10000 // optional timeout in ms\n        },\n        waitForMillis: 15000 // optional \"sleep\" in ms to consider the page as \"settled\"\n    }]\n});\n\nconst { session, error } = call.output;\n\n// if it fails, the error will be filled with something\n// otherwise, the session will have the Session parameters, that can be\n// instantiated manually using `new Apify.Session({ ...session, sessionPool })`\n\n// load the session pool from the storage, so it has our new\n// session. this might change in the future\nconst sessionPool = await Apify.openSessionPool({\n    persistStateKeyValueStoreId: storageName\n});\n\nconst sessionJustCreated = sessionPool.sessions.find(s =\u003e s.id === session.id);\n\n/**\n * the complete Cookie string for usage on the header\n */\nsessionJustCreated.getCookieString('http://example.com');\n\n/**\n * contains the User-Agent used for the login request.\n * the same userAgent must be set between uses so there's no\n * conflict and blocks. Set this as your User-Agent header\n **/\nsessionJustCreated.userData.userAgent;\n\n/**\n * the proxyUrl used, can be empty.\n * Set this as your proxyUrl parameter in crawlers.\n *\n * This might be undefined if you didn't use any proxies\n */\nsessionJustCreated.userData.proxyUrl;\n\n/**\n * object containing any sessionStorage content, useful for JWT tokens.\n * Useful for using in PuppeteerCrawler\n */\nsessionJustCreated.userData.sessionStorage;\n\n/**\n * object containing any localStorage content, useful for JWT\n * tokens. Useful for using in PuppeteerCrawler\n */\nsessionJustCreated.userData.localStorage;\n\n```\n\n## Login locally then use the session on the platform\n\nYou can login locally, executing the login-session actor on your machine, make sure you're logged in to the platform using `apify login` and using `forceCloud` input option, like this:\n\n```jsonc\n{\n    \"username\": \"username\",\n    \"password\": \"s3cr3tp4ssw0rd\",\n    \"website\": [{ \"url\": \"https://example.com/\" }],\n    \"sessionConfig\": {\n        \"storageName\": \"example-login-sessions\" // need to use this\n    },\n    \"steps\": [\n        {\n            \"username\": { \"selector\": \"#email\" },\n            \"password\": { \"selector\": \"#password\" },\n            \"submit\": { \"selector\": \"input[type=\\\"submit\\\"]\" },\n            \"success\": { \"selector\": \".main-menu\", \"timeoutMillis\": 10000 },\n            \"failed\": {\n                \"selector\": \".login.error\",\n                \"timeoutMillis\": 10000\n            },\n            \"waitForMillis\": 30000\n        }\n    ],\n    \"cookieDomains\": [\"https://example.com\"],\n    \"proxyConfiguration\": {\n        \"useApifyProxy\": false\n    },\n    \"forceCloud\": true // this forces the login to be saved on platform Storage (https://my.apify.com/storage#/keyValueStores)\n}\n```\n\nPlace this in your `apify_storage/key_value_stores/default/INPUT.json` file, then run locally:\n\n```\n$ apify run --purge\n```\n\nThe session will be created in your Apify platform account, under the `storageName` you provided, but using your local IP.\nUsing this, you're able to avoid PIN requests and security checkpoint screens.\n\n## Input Recipes\n\nHere are some real-life examples of INPUT.json that you may use:\n\n### Gmail\n\n```json\n{\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"website\": [{ \"url\": \"https://accounts.google.com/signin/v2/identifier?service=mail\u0026passive=true\u0026flowName=GlifWebSignIn\u0026flowEntry=ServiceLogin\" }],\n    \"cookieDomains\": [\n        \"https://mail.google.com\",\n        \"https://accounts.google.com\",\n        \"https://google.com\"\n    ],\n    \"steps\": [{\n        \"username\": {\n            \"selector\": \"#identifierId\"\n        },\n        \"submit\": {\n            \"selector\": \"#identifierNext\"\n        },\n        \"success\": {\n            \"selector\": \"input[type=\\\"password\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"failed\": {\n            \"selector\": \"#identifierId[aria-invalid=\\\"true\\\"],iframe[src*=\\\"CheckConnection\\\"]\"\n        },\n        \"waitForMillis\": 30000\n    }, {\n        \"password\": {\n            \"selector\": \"input[type=\\\"password\\\"]\"\n        },\n        \"submit\": {\n            \"selector\": \"#passwordNext\",\n            \"timeoutMillis\": 15000\n        },\n        \"failed\": {\n            \"selector\": \"input[type=\\\"password\\\"][aria-invalid=\\\"true\\\"],iframe[src*=\\\"CheckConnection\\\"]\",\n            \"timeoutMillis\": 5000\n        },\n        \"success\": {\n            \"selector\": \"link[href*=\\\"mail.google.com\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"waitForMillis\": 30000\n    }]\n}\n```\n\n### Facebook\n\n```json\n{\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"website\": [{ \"url\": \"https://www.facebook.com/\" }],\n    \"cookieDomains\": [\n        \"https://facebook.com\"\n    ],\n    \"steps\": [{\n        \"username\": {\n            \"selector\": \"#login_form [type=\\\"email\\\"]\"\n        },\n        \"password\": {\n            \"selector\": \"#login_form [type=\\\"password\\\"]\"\n        },\n        \"submit\": {\n            \"selector\": \"#login_form [type=\\\"submit\\\"]\"\n        },\n        \"success\": {\n            \"selector\": \"body.home\",\n            \"timeoutMillis\": 10000\n        },\n        \"failed\": {\n            \"selector\": \"body.login_page,body.UIPage_LoggedOut\",\n            \"timeoutMillis\": 10000\n        },\n        \"waitForMillis\": 30000\n    }]\n}\n```\n\n### Twitter\n\n```json\n{\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"website\": [{ \"url\": \"https://twitter.com/login\" }],\n    \"cookieDomains\": [\n        \"https://twitter.com\"\n    ],\n    \"steps\": [{\n        \"username\": {\n            \"selector\": \"h1 ~ form [name=\\\"session[username_or_email]\\\"]\",\n            \"timeoutMillis\": 2000\n        },\n        \"password\": {\n            \"selector\": \"h1 ~ form [name=\\\"session[password]\\\"]\",\n            \"timeoutMillis\": 2000\n        },\n        \"submit\": {\n            \"selector\": \"h1 ~ form [role=\\\"button\\\"][data-focusable]\"\n        },\n        \"success\": {\n            \"selector\": \"h2[role=\\\"heading\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"failed\": {\n            \"selector\": \"h1 ~ form [role=\\\"button\\\"][disabled]\",\n            \"timeoutMillis\": 10000\n        },\n        \"waitForMillis\": 30000\n    }]\n}\n```\n\n### Instagram\n\n```json\n{\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"website\": [{ \"url\": \"https://instagram.com\" }],\n    \"cookieDomains\": [\n        \"https://www.instagram.com\"\n    ],\n    \"steps\": [{\n        \"username\": {\n            \"selector\": \"input[name=\\\"username\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"password\": {\n            \"selector\": \"input[name=\\\"password\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"submit\": {\n            \"selector\": \"button[type=\\\"submit\\\"]\"\n        },\n        \"success\": {\n            \"selector\": \"img[alt=\\\"Instagram\\\"]\",\n            \"timeoutMillis\": 10000\n        },\n        \"failed\": {\n            \"selector\": \"#slfErrorAlert\",\n            \"timeoutMillis\": 5000\n        },\n        \"waitForMillis\": 30000\n    }]\n}\n```\n\n### LinkedIn\n\n```jsonc\n{\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"website\": [\n        {\n            \"url\": \"https://www.linkedin.com/login?fromSignIn=true\u0026trk=guest_homepage-basic_nav-header-signin\"\n        }\n    ],\n    \"steps\": [\n        {\n            \"username\": {\n                \"selector\": \"#username\"\n            },\n            \"password\": {\n                \"selector\": \"#password\"\n            },\n            \"submit\": {\n                \"selector\": \".login__form_action_container button\"\n            },\n            \"success\": {\n                \"selector\": \".authentication-outlet,.launchpad-cp-enabled\",\n                \"timeoutMillis\": 15000\n            },\n            \"failed\": {\n                \"selector\": \".form__input--error,.login__form,.pin-verification-form\",\n                \"timeoutMillis\": 15000\n            },\n            \"waitForMillis\": 30000\n        }\n    ],\n    \"cookieDomains\": [\"https://www.linkedin.com\"]\n}\n```\n\n## Related Content\n\n* [Log in to website by transferring cookies from web browser (legacy)](https://help.apify.com/en/articles/1444249-log-in-to-website-by-transferring-cookies-from-web-browser-legacy)\n* [How to log in to a website using Puppeteer](https://help.apify.com/en/articles/1640711-how-to-log-in-to-a-website-using-puppeteer)\n* [Session Management](https://sdk.apify.com/docs/guides/session-management)\n\n## Caveats\n\n* Apify proxy sessions can last at most 24h, so never set your `maxAgeSecs` greater than this number\n* If the proxy fails, the login fails. If the proxy is banned, the login fails.\n\n## Example\n\nExample form is in [https://now-h3p8398gc.now.sh](https://now-h3p8398gc.now.sh)\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fapify-login-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpocesar%2Fapify-login-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fapify-login-session/lists"}