-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Allow Ferrum to use default (non incognito) context #47
Comments
Absolutely, go ahead! I just didn’t need it thus it was easy not to implement rather than implement. I think it will be as easy as provide a path and just don’t remove anything from it when quitting. |
I think the default context that Chrome creates has a lot of limitations like inability to create pages inside it and so on. If you come up with something useful please open a PR but due to inactivity I'm going to close this issue. |
Hi, |
@yann120 http is stateless protocol. The state is determined by headers sent from/to web server. If you want to login on the website, close browser and then open it and be logged in, you need to store your cookies somewhere, and next time before telling a browser to visit url, load those cookies. You open the page and login: browser = Ferrum::Browser.new(headless: false)
page = browser.create_page
page.go "https://auth.udacity.com/sign-in?next=https%3A%2F%2Flearn.udacity.com%2F"
page.network.wait_for_idle
page.at_xpath("//*[@id='email']").focus
page.keyboard.type(email)
page.at_xpath("//*[@id='revealable-password']").focus
page.keyboard.type(password)
button = page.at_xpath("//button[@type='button'][./span[.='Sign in']]")
button.focus.click
page.network.wait_for_idle
File.open(path, "w") do |file|
file.write(page.cookies.map(&:to_h).to_yaml)
end Then next time you load all the cookies before opening the page: browser = Ferrum::Browser.new(headless: false)
page = browser.create_page
cookies = YAML.load_file(path)
cookies.each { |c| page.cookies.set(c) }
page.go "https://learn.udacity.com" |
Thanks, I ended up using your solution and it work :) |
I'd like my browser state/session to be preserved between uses of my script.
Currently, Ferrum places all commands inside a BrowserContext, which acts like an Incognito session and doesn't load stored cookies.
I would like to use the browser's default session (which isn't inside a context), and take advantage of the
--user-data-dir
flag to be able to persist state across sessions. This would require modifying how Ferrum uses and creates contexts to allow for non-browserContext requests. I am happy to do this, and submit a PR, but would like some author feedback (if possible) about whether such an option is in line with the project's vision before I start working on code for this.The text was updated successfully, but these errors were encountered: