joelgriffith / navalia

A bullet-proof, fast, and reliable headless browser API
https://joelgriffith.github.io/navalia/
GNU General Public License v3.0
957 stars 33 forks source link

Connect to remote Chrome instances #28

Closed priithaamer closed 7 years ago

priithaamer commented 7 years ago

Currently, this library seems to rely on chrome-launcher when it comes to connecting to chrome instances. Would it make sense to have alternative way of connecting to already running instances during Navalia initialization? I wouldnt mind working on this because i have huge need for this and i really like navalia's api.

I happen to have use case where i have number of VMs running headless chrome and i can connect to them over the remote debugging protocol. It becomes useful when using chrome from AWS Lambda functions, for example.

Anyway, thanks for the fresh approach in browser driver landscape. I've been looking forward to this for some time by now. Cheers!

joelgriffith commented 7 years ago

I think this is a fabulous idea, and definitely within the realm of this project! I'd love to see a PR if you're willing to try out a contribution 😄

There's a few place you can start: the first by adding a parameter to Navalia's constructor to specify where the browsers are. When starting chrome, you can pass in a port for remote debuggers to connect, which is what you'd have to do. As far as the API might go, I think something like:

const navalia = new Navalia({
  chromeOptions: {
    remote: ['http://www.my-site.com:1234', 'http://www.my-site.com:4567'],
  }
});

Navalia starts Chrome here, so we'll need to alter some utilities to allow passing in an existing chrome instance. There'd also be other work in the "cleanup" portion of the library as well, as Navalia will try and close these on shutdown or when maximums are reached here, which we probably don't want it to do.

Let me know if how I can help guide or give feedback, but definitely say give it a shot! We're open to it!

joelgriffith commented 7 years ago

I can take care of all the tedious parts (docs, changelog, releasing), so don't worry about those ceremonious tasks

priithaamer commented 7 years ago

Hey, thanks for pointing out where to start! I was reading through the code earlier and it is also easy to follow. Anyway, i will start working on it soon.

joelgriffith commented 7 years ago

Hey @priithaamer, just checking in with you on this. I can knock this out if it's a blocker for you?

priithaamer commented 7 years ago

Hey, i'm not in a hurry with this. Feel free to work on more urgent issues. Currently, i have my own wrapper for chrome-remote-interface that is quite similar to navalia. However, i would like to use well maintained library eventually and this project here is a perfect replacement.

joelgriffith commented 7 years ago

Been a few days! The Chrome module now supports this (I'm working on getting it into the Navalia Module next).

npm i --save navalia@1.1.0 🎉

priithaamer commented 7 years ago

Whoa, that was quick! I'll try it out in the next couple of days.