-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening page after setting cookies from previously saved cookies does not work (not logged in) #717
Comments
@JoelEinbinder could you please take a look? |
It works fine for me. Are you trying to immediately set the cookies after you click the button? You have to wait for the login to successfully complete first. page.click('#login-submit'); // no await here
await page.waitForNavigation();
console.log(await page.cookies()); |
For some reasons, I had issues with the page.waitForNavigation() call. It kept on waiting until it timed out (even with the option waitUntil=networkidle). So currently, my only option is to wait for 10 sec, and it works ! So there is no issues with cookies, sorry about that, it's a page loading matter. |
@xavatar , do you mind share the code to write cookies to file, i have problem on that. ThankU! |
Hey @nanhaiyufu , My code is wrapped into an object context, hence the this._page and other this.xxx properties references. But the main essence is:
|
@xavatar would you mind sharing a script (either here or in a new issue) where the |
I don't have the initial script anymore, but basically the steps are easy to reproduce:
I simply replaced the waitForNavigation step with a waitFor(10000), as it seemed to load forever... Hope this could help. |
@xavatar the following works for me on current tip-of-tree (0.11.0-alpha): const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://linkedin.com');
await page.focus('input.login-email');
await page.type('login'); // your login here
await page.focus('input.login-password');
await page.type('password'); // your password here
page.click('.submit-button');
await page.waitForNavigation();
console.log('done!');
await page.close();
await browser.close();
})(); |
Yes, but the issue was getting the good cookies right away after the waitForNavigation() step, which did not seem to work properly, hence the need to add a waitFor(time) in my case. However I haven't been able to reproduce this error every time, it's random... weird : / |
@xprudhomme Thank you for sharing your code. It was very helpful! |
Wonderful ! Thanks for sharing. |
This seems to be related to #921, which was recently fixed and should be already working fine in 1.10.0. |
** Environment:**
** Steps to reproduce?**
First step:
(Everything works fine up to here, we are logged-in and the cookies are valid, and well saved, I've checked).
Second step:
Code that reproduces the issue.
Cookies are retrieved with the page.cookies method, and then saved to a local file with fr.writeFile (works fine)
let cookies = await page.cookies();
Retrieve cookies from file (using fs.readFile, works fine too), and inject them using this method:
` /**
* Inject cookies from previously saved cookies file
* @param {string} file
*/
async injectCookiesFromFile(file) {
}`
Open page
await page.goto("https://www.linkedin.com/");
Note:
Using either method (1) or (2) (i.e. using a loop or using the spread operator) does not change anything.
Expected result?
Once the cookies have been set/injected with previously saved cookies, when we open the page, we should already be logged-in
What happens instead?
It seems the page.setCookie() had no effect, as when opening the page results in being still logged-out.
Any idea why the cookies seem to have no effect once injected?
The text was updated successfully, but these errors were encountered: