kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.
MIT License
520 stars 15 forks source link

Allow setting Firefox profile path so jupynium can remember passwd or token #17

Closed fecet closed 1 year ago

fecet commented 1 year ago

I have play jupynium for a while and it works like a charm, however I found it's annoying to enter token(passwd) everytime. A simple but less elegant way is to make selenium refer to default profile:

def webdriver_firefox():
    profile = webdriver.FirefoxProfile("/home/username/.mozilla/firefox/7kl5jw0d.default-release/")
    profile.set_preference("browser.link.open_newwindow", 3)
    profile.set_preference("browser.link.open_newwindow.restriction", 0)
    # profile.setAlwaysLoadNoFocusLib(True);
    return webdriver.Firefox(profile, service_log_path=os.path.devnull)

the directory can be found by https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data#w_how-do-i-find-my-profile. ("~" refer to home seems not work for me btw).

This is good enough for me, but I'm sure you have better ideas :)

kiyoon commented 1 year ago

Hi, I can add an option to set the profile directory, with expanding ~ as well.
Another good solution can be #12. When this gets implemented it will be easier to open the notebook whenever you need.

Thanks for the feedback!

kiyoon commented 1 year ago

Do you also have the file profile.ini? I think it is more elegant to provide a path to that file so you don't need to configure the directory every machine differently

fecet commented 1 year ago

Just knew profile.ini is a thing, so it's definitely a better way.

I usually connect to a remote hosted notebook, so I guess #12 does not help me a lot?

kiyoon commented 1 year ago

I see, actually for me I do both a lot. I'll make the profile option available soon

kiyoon commented 1 year ago

This has been implemented. Please try and let me know! Thanks for such a cool suggestion!

fecet commented 1 year ago

The default profile for me seems not as expected, it's look like

[Install4F96D1932A9F858E]
Default=nlk07dgt.default-release
Locked=1

[Profile1]
Name=default
IsRelative=1
Path=smhzf393.default
Default=1

[Profile0]
Name=default-release
IsRelative=1
Path=nlk07dgt.default-release

[General]
StartWithLastProfile=1
Version=2

And I have to manually set profile0 default as 1 and delete that for profile 1. That's not a big deal but worth noting.

However, that function works fine for me out of neovim:

from jupynium.cmds.jupynium import webdriver_firefox

driver=webdriver_firefox()

But in :JupyniumStartAndAttachToServer it still open a firefox which profile located in a random tmp dir.

Edit: I check about:profiles for start jupynium in and out neovim, they are identical, but if open under neovim, the language setting and add-ons are disapper and looks like a brand new firefox.

kiyoon commented 1 year ago

I put the option in the nvim setup as well. Can you pass firefox_profile_name = "default-release"? I don't know why some settings have weird defaults..

Or maybe the firefox_profiles_ini_path is wrong. If it can't be read correctly it will open without a profile directory like before.

require("jupynium").setup({
  -- Used to remember the last session (password etc.).
  -- You may need to change the path.
  firefox_profiles_ini_path = vim.fn.isdirectory(vim.fn.expand "~/snap/firefox/common/.mozilla/firefox")
      and "~/snap/firefox/common/.mozilla/firefox/profiles.ini"
    or "~/.mozilla/firefox/profiles.ini",
  firefox_profile_name = "default-release", -- nil means the default profile
})
fecet commented 1 year ago

Weird thing is Lua style conditional operator break something, I have to explicitly set

firefox_profiles_ini_path = "~/.mozilla/firefox/profiles.ini",

And then the behavior of ":JupyniumStartAndAttachToServer " and "jupynium" in cli agree. (Otherwise the previous one will open firefox without add-ons, settings, account, etc, but about:profiles do say it open with the correct profile)

Not sure if I'm the only one with this problem, I think you can ignore it until someone else report the same issue if you cannot reproduce.

kiyoon commented 1 year ago

Maybe you also have the snap directory? Or is my code just wrong..