How to run Headless Chrome Remotely using Browserless.
This is part 1 of my post on Serverless Instagram Bot using Docker and Azure Functions.
Headless Chrome is a way to run the Chrome browser in a headless environment without the full browser UI.
My idea is to load www.instagram.com
in a headless chrome browser and use, Puppeteer scripts, Vanilla JS and jQuery to automate browsing and social media app interactions like commenting. If you want to know why I am doing this, check out How to code: Serverless Instagram Bot using Docker and Azure Functions.
Browserless runs Puppeteer in a Docker instance with all the libraries and setup code installed and configured. All I have to do is connect to the deployed Docker container or instance and I can write the scripts that will load and interact with www.instagram.com
.
Setup an Instance of Browserless🚨
Install Browserless on your machine
On the github.com page, Browserless has a simple installation guide which you should follow if you are installing Browserless on your local machine or on a remote server or virtual machine. You should already be familiar with Docker if you are going to pull this off.
Open your terminal if you are using Linux and Command Prompt on Windows.
➡️Pull image by typing docker pull browserless/chrome
.
↪️Type docker images
to verify the image has been downloaded locally.
️↪️Run image to start the container docker run -p <your host_port:app_port eg "3000:3000"> browserless/chrome
Ok at this point I lost everything I had typed in this post from here on. Medium didn’t save the progress made. I had to rewrite it. 😠
On an Azure Container
I thought about using Azure Container Instances to also create a Browserless container. I logged into my Azure portal and clicked Create a Resource -> Containers -> Container Instances. Watch the animation below for how I filled the setup form.
The container name can be anything you want to label it as. The Container Image should be browserless/chrome
. If you select a DNS name label, you can use the FQDN to access the Browserless container instance instead of the IP address.
Either way, on Azure Containers or on my local machine or virtual machine, I could trigger the Browserless instance by visiting http://<my IP address or my container IP address or FQDN>:3000
. This is what I saw 👇 .
The window shows an editor on the left and a preview screen on the right. You can now connect run your Puppeteer scripts or test them by writing code on the left and hitting debug.
I write my first Puppeteer script in the next post. I was able to login to www.instagram.com
and load my timeline using this script.
If you have not used Puppeteer before, you can checkout this Chrome addon that generates scripts for you as you browse. That’s how I learnt to use it.
I’m getting closer step by step.
👏Please clap. Please share this post. 👏
I appreciate claps if you ❤️ this post. Stay with me for Another DIY Javascript Experiment and dope coding topics including Machine Learning, React ecosystem, Linux and anything Javascript does.