Skip to content
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 extensions? #61

Closed
sebyx07 opened this issue Apr 4, 2020 · 12 comments
Closed

Allow Ferrum to use extensions? #61

sebyx07 opened this issue Apr 4, 2020 · 12 comments

Comments

@sebyx07
Copy link
Contributor

sebyx07 commented Apr 4, 2020

Hey, currently It doesn't work to add extensions(Use them I mean)

I've tried to run it without headless enabled and they do really load.

But they load only in the initial window, the ferrum provided tabs don't have access to them :/

@route
Copy link
Member

route commented Apr 5, 2020

Hey, unfortunately it's Chrome limitation and there's nothing Ferrum can do here. In headless mode they are all turned off, in headful mode they should work though I didn't test it.

@route route closed this as completed Apr 5, 2020
@sebyx07
Copy link
Contributor Author

sebyx07 commented Apr 5, 2020

It's not working, that's the problem. Here I've disabled headless mode.
The first image shows the default tab(page/window)
https://ibb.co/rx1TNws

Then the 2nd where the visit happens. It opens a new window in chrome where it's incognito

https://ibb.co/G7Xxjm6

@sebyx07
Copy link
Contributor Author

sebyx07 commented Apr 5, 2020

I didn't try to load any extension now, but usually, incognito no extension is enabled. Is there a way to just control the first window?

@route
Copy link
Member

route commented Apr 5, 2020

You should play around with Chrome flags https://github.com/rubycdp/ferrum/blob/master/lib/ferrum/browser/chrome.rb#L63 set the Profile folder, create one common context for all pages or the default one and then use it for all of them.

@route
Copy link
Member

route commented Apr 6, 2020

All good? Did you manage to solve it? I see what you mean. I'll try to investigate it.

@route route reopened this Apr 6, 2020
@route
Copy link
Member

route commented Apr 6, 2020

It's Chrome's limitation, if you run Ferrum with headless: false there will be one created context already as you can see a visible window:

browser = Ferrum::Browser.new(headless: false)
context_params = browser.command("Target.getBrowserContexts")["targetInfos"].select { |c| c["type"] == "page" }.first
context = Context.new(browser, browser.contexts, context_params["browserContextId"])

but unfortunately you won't be able to create pages inside this context:

context.create_page
Traceback (most recent call last):
       16: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
       15: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/exe/bundle:30:in `block in <top (required)>'
       14: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:18:in `start'
       13: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
       12: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:27:in `dispatch'
       11: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
       10: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
        9: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        8: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:496:in `console'
        7: from /home/route/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/console.rb:19:in `run'
        6: from (irb):30
        5: from /home/route/Projects/Ruby/ferrum/lib/ferrum/context.rb:41:in `create_page'
        4: from /home/route/Projects/Ruby/ferrum/lib/ferrum/context.rb:45:in `create_target'
        3: from /home/route/Projects/Ruby/ferrum/lib/ferrum/browser.rb:83:in `command'
        2: from /home/route/Projects/Ruby/ferrum/lib/ferrum/browser/client.rb:48:in `command'
        1: from /home/route/Projects/Ruby/ferrum/lib/ferrum/browser/client.rb:90:in `raise_browser_error'
Ferrum::BrowserError (Failed to find browser context with id D2FDBFAC3A0AE8F6826B778A5DA94968)

Though you are able to get current target and visit given url:

target_params = browser.command("Target.getTargetInfo", targetId: context_params["targetId"])["targetInfo"]
target = Target.new(browser, target_params)
target.page.goto("http://github.com")

so it's only one page per visible window, you can only create pages in new contexts.

@route route closed this as completed Apr 6, 2020
@sebyx07
Copy link
Contributor Author

sebyx07 commented Apr 8, 2020

I could load it. But no luck with controlling the extension. you know.
chrome-extension://cknebhggccemgcnbidipinkifmmegdel/html/welcome.html

I've tried your solution, but
browser.command("Target.getBrowserContexts")["targetInfos"]

I get it as nil

@route
Copy link
Member

route commented Apr 9, 2020

Then Chrome doesn't allow this I think

@alexanderadam
Copy link
Contributor

The first image shows the default tab(page/window) […]
Then the 2nd where the visit happens.

I was also wondering why there are always two windows. One "regular" one and an Incognito one. Maybe it is because incognito mode usually restricts the usage of extensions?

And just to clarify this:

Puppeteer is also using CDP and explicitly mentions that it is indeed possible to use extensions in non-headless mode. By adding --load-extension.
So maybe ferrum is just missing a proper abstraction for it at the moment?

@route
Copy link
Member

route commented May 20, 2020

@alexanderadam I tried to use extension in the past to workaround proxy limits in headless chrome and this flag in particular didn't work. It only worked in headful mode. Things might have changed though I I didn't check it because Chrome dev team clearly stated in the past that extensions are not allowed.

@alexanderadam
Copy link
Contributor

It only worked in headful mode.

This is what I wrote (it is indeed possible to use extensions in non-headless mode.). 😉

@route
Copy link
Member

route commented May 20, 2020

Yea headful mode allows it. Sorry I missed it too many switches between tasks lol)

sigmike pushed a commit to ouvrages/ferrum that referenced this issue Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants