<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saurabh Panja on Medium]]></title>
        <description><![CDATA[Stories by Saurabh Panja on Medium]]></description>
        <link>https://medium.com/@panjasaurabh?source=rss-f58c5461d9ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Saurabh Panja on Medium</title>
            <link>https://medium.com/@panjasaurabh?source=rss-f58c5461d9ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:36:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@panjasaurabh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Get an overview of hapi.js by building a URL shortener]]></title>
            <link>https://medium.com/@panjasaurabh/get-an-overview-of-hapi-js-by-building-a-url-shortener-18bfa3044e6a?source=rss-f58c5461d9ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/18bfa3044e6a</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[hapijs]]></category>
            <dc:creator><![CDATA[Saurabh Panja]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 18:03:07 GMT</pubDate>
            <atom:updated>2020-03-23T18:58:06.752Z</atom:updated>
            <content:encoded><![CDATA[<h3>Get an overview of hapi.js by building an URL shortener application.</h3><p>Microframeworks like <a href="https://hapi.dev/">hapi.js</a> are one of the many choices preferred for <strong>enterprise-grade</strong> backend needs. Originally it was developed by <strong>Walmart</strong> to scale their application during <strong>Black Friday</strong> sale.</p><figure><img alt="hapi.js logo" src="https://cdn-images-1.medium.com/max/500/1*62eKElOUfXJh8WVa-7oMrQ.png" /></figure><p>Micro frameworks are preferred in a microservice architecture. Because of obvious reasons i.e they are lightweight and can be easily scalable.</p><p>To read more about hapi.js <a href="http://hapi.dev/">click here</a>.</p><p>To get an idea of how hapi.js works. We will build a simple URL shortener application and learn more about it in the process.</p><p>So let’s get started.</p><p>If you have some knowledge of working with any microframework like <em>flask</em> or <em>express, i</em>t would be a plus. Even if you have never worked on any microframework, do not worry. I have got you covered. 😉</p><p><strong><em>Important</em></strong><em>: Make sure you have</em><strong><em> nodejs 12.*</em></strong><em>+ version, </em><strong><em>npm, MongoDB</em></strong><em> installed on your system.</em></p><p>Create a directory</p><pre>mkdir url-shortener<br>cd url-shortener</pre><p>Initialize the directory with package.json by running</p><pre>npm init</pre><p>Install dependencies</p><pre>npm i @hapi/hapi @hapi/vision ejs mongoose shortid --save</pre><p>Once you install the dependencies your package.json <em>dependencies</em> should look something like this.</p><p><strong>package.json</strong></p><pre>&quot;dependencies&quot;: {</pre><pre>&quot;@hapi/hapi&quot;: &quot;^19.1.1&quot;,</pre><pre>&quot;@hapi/vision&quot;: &quot;^6.0.0&quot;,</pre><pre>&quot;ejs&quot;: &quot;^3.0.1&quot;,</pre><pre>&quot;mongoose&quot;: &quot;^5.9.2&quot;,</pre><pre>&quot;shortid&quot;: &quot;^2.2.15&quot;</pre><pre>}</pre><p><em>**If you have trouble running the app, do install with the version mentioned above**</em></p><p>Let’s go through the dependencies.</p><p>“@hapi/hapi” installs hapi.js.</p><p>“@hapi/vision” will be used for running template rendering engines. It can handle almost all rendering engines like ejs, pug.js, handlebar.js.</p><p>“ejs” is our template rendering engine. As a rendering engine, it helps us in writing conditions and loops in our HTML. It renders data from the server-side to the client-side.</p><p>“mongoose” to use the MongoDB database with our application.</p><p>“shortid” is a small library that will help us to generate short small length unique string(that will be our short URL).</p><p>For styling the HTML I am using Semantic-UI. Nothing against bootstrap, bootstrap is easier to use. But I personally find semantic-ui cleaner and more responsive then bootstrap. (semantic-ui tables are responsive, bootstrap doesn’t provide responsive tables)</p><p>Let’s look through the code, and understand it.</p><h4>Directory Structure.</h4><pre>| — app.js</pre><pre>| — models<br>| — | — shortUrl.js(models/shortUrl.js)</pre><pre>| — views<br>| — | — index.ejs(views/index.ejs)</pre><pre>| - package.json</pre><pre>| - package-lock.json</pre><pre>| - node_modules</pre><p><strong>app.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0003cd2c97798f85d5a4220735d03831/href">https://medium.com/media/0003cd2c97798f85d5a4220735d03831/href</a></iframe><p><strong>models/shortUrl.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2c0f68543be3813529eb4274de642ce/href">https://medium.com/media/a2c0f68543be3813529eb4274de642ce/href</a></iframe><p><strong>views/index.ejs</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d024544241f1bf687d838b4b969849ee/href">https://medium.com/media/d024544241f1bf687d838b4b969849ee/href</a></iframe><p>If you are familiar with Model View Controller (MVC) architecture. The directory structure would make sense to you. Here ‘app.js’ is our controller. ‘shortUrl.js’ is our model to store full and short URLs. ‘index.ejs’ is our views to display all the URLs.</p><p>Let’s understand the app first by walking through the code. Let’s start by understanding the model first.</p><p><strong>models/shortUrl.js</strong></p><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const shortId = require(&#39;shortid&#39;)</pre><p>Requiring necessary dependencies. As noted earlier ‘mongoose’ will be our ORM(Object-Relational Mapper)to communicate with MongoDB database, and ‘shortId’ will help us to generate short URL for long URLs.</p><p><strong>models/shortUrl.js</strong></p><pre>let shortUrlSchema = new mongoose.Schema({</pre><pre>fullUrl: {</pre><pre>type: String,</pre><pre>required: true,</pre><pre>},</pre><pre>shortUrl: {</pre><pre>type: String,</pre><pre>default: shortId.generate</pre><pre>},</pre><pre>count: {</pre><pre>type: Number,</pre><pre>default: 0,</pre><pre>}</pre><pre>});</pre><pre>let ShortUrl = mongoose.model(&#39;ShortUrl&#39;, shortUrlSchema);</pre><pre>module.exports = ShortUrl</pre><p>The schema for our model is as given above. We are storing fullUrl, shortUrl, and count. Here count is the number of times the short URL has been visited.</p><p>If you have noticed the default parameter for ‘shortUrl’ is ‘shortId.generate’. ‘shortId.generate’ as the name suggests is a function that generates a short string for our long URL. Every time we save a long URL in the DB, simultaneously a short URL is generated and stored in the database. Since the count has default value 0. Whenever a short URL is saved the initial count is set to zero.</p><p><strong>app.js</strong></p><pre>&#39;use strict&#39;;</pre><pre>const Hapi = require(&#39;@hapi/hapi&#39;);</pre><pre>//database connectivity</pre><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const mongodbURL = &quot;mongodb://localhost/url-shortener&quot;;</pre><pre>mongoose.connect(mongodbURL, {</pre><pre>useNewUrlParser: true,</pre><pre>useUnifiedTopology: true</pre><pre>}).then(() =&gt; console.log(&quot;Connected&quot;));</pre><pre>//model for our application</pre><pre>const ShortUrl = require(&#39;./models/shortUrl&#39;)</pre><pre>...</pre><p>Requiring necessary dependencies, connecting the MongoDB database and importing the model to our application. ShortUrl is the model that we have defined in our models folder. It is imported here.</p><p><strong>app.js</strong></p><pre>...<br>const server = Hapi.server({</pre><pre>port: 8000,</pre><pre>});</pre><pre>await server.register(require(&#39;@hapi/vision&#39;));</pre><pre>server.views({</pre><pre>engines: {</pre><pre>ejs: require(&#39;ejs&#39;)</pre><pre>},</pre><pre>relativeTo: __dirname,</pre><pre>path: &#39;views&#39;</pre><pre>});<br>...</pre><p>Here we are creating a server and running it on port 8000. The app will be visible on <a href="https://localhost:8000/">http://localhost:8000/</a></p><p>We are registering ‘vision’ to run our view engine ‘ejs’ in our application.</p><p>We are declaring ‘ejs’ as our engine and specifying the folder ‘views’ as our directory to store the ejs file. The folder is relative to ‘__dirname’ where ‘__dirname’ is the path from which the app is run.</p><p>Since we are mentioning the path here, we do not have to write the absolute path of our view file in our handler function.</p><p><strong>app.js</strong></p><pre>...<br>server.route({</pre><pre>method: &#39;GET&#39;,</pre><pre>path: &#39;/&#39;,</pre><pre>handler: async (request, h) =&gt; {</pre><pre>return await h.view(&#39;index&#39;)</pre><pre>}</pre><pre>});<br>...</pre><p>‘server.route’ handles the routing for us. When the client makes a get request at the ‘/’ path in our app, namely it is called the index route. This will be the landing page of our application.</p><p>As soon as the client visits the path, it is handled by the ‘handler’. The anonymous function takes two arguments. That helps in how to handle the request and respond to it.</p><p><strong>views/index.ejs</strong></p><pre>...<br>&lt;form <em>class</em>=&quot;ui form&quot; <em>action</em>=&quot;/&quot; <em>method</em>=&quot;POST&quot;&gt;</pre><pre>&lt;div <em>class</em>=&quot;field&quot;&gt;</pre><pre>&lt;input <em>type</em>=&quot;text&quot; <em>name</em>=&quot;full-url&quot; <em>placeholder</em>=&quot;Enter URL here&quot;&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;button <em>class</em>=&quot;ui primary button&quot; <em>type</em>=&quot;submit&quot;&gt;Submit&lt;/button&gt;</pre><pre>&lt;/form&gt;<br>...</pre><p>**<em>Ignore the classes, they are semantic-ui CSS classes used for styling.</em></p><p>This will create a form for us. This form will make a <strong>POST </strong>request at the path ‘/’ when we fill the <em>input </em>field with a long URL and submit it.</p><p>Let’s check out how to handle <strong>POST </strong>requests in <em>hapi.js</em></p><p><strong>app.js</strong></p><pre>...<br>server<strong>.</strong>route({</pre><pre><em>method</em>: &#39;POST&#39;,</pre><pre><em>path</em>: &#39;/&#39;,</pre><pre>handler: <em>async</em> (<strong>request</strong>, <strong>h</strong>) <strong>=&gt;</strong> {</pre><pre>let fullUrl <strong>=</strong> <strong>request.</strong><em>payload</em>[&#39;full-url&#39;];</pre><pre><strong>await</strong> ShortUrl<strong>.</strong>create({</pre><pre><em>fullUrl</em>: fullUrl</pre><pre>}, (<strong>err</strong>) <strong>=&gt;</strong> {</pre><pre><strong>if</strong> (<strong>err</strong>) {</pre><pre>console<strong>.</strong>log(<strong>err</strong>)</pre><pre>}</pre><pre>});</pre><pre><strong>return</strong> <strong>h.</strong>redirect(&#39;/&#39;)</pre><pre>}</pre><pre>});</pre><pre>...</pre><p>To handle a <strong>POST </strong>request. We need to specify our method as <em>POST </em>and specify its path. Inside the handler, we are extracting the <em>‘full-url’</em> and storing it to our DB. After it is saved, we are redirecting to the index page.</p><p>To extract the <em>full-url </em>from the request, we are using the built-in <em>‘payload’ </em>API.</p><pre>let fullUrl = request.<strong>payload</strong>[&#39;full-url&#39;]</pre><p>As we have specified,‘<em> shortId.generate ’ </em>as our default in the<strong> models/shortUrl.js</strong> . It will create a short URL for us when we save long URL in our DB.</p><p><strong>models/shortUrl.js</strong></p><pre>...<br><em>shortUrl</em>: {</pre><pre><em>type</em>: <em>String</em>,</pre><pre>default: shortId<strong>.</strong><em>generate</em></pre><pre>}</pre><pre>...</pre><p><strong>Next, </strong>let’s understand the logic to show all the URLs along with the short URL in the index page.</p><p><strong>app.js</strong></p><pre>...<br>server<strong>.</strong>route({</pre><pre><em>method</em>: &#39;GET&#39;,</pre><pre><em>path</em>: &#39;/&#39;,</pre><pre>handler: <em>async</em> (<strong>request</strong>, <strong>h</strong>) <strong>=&gt;</strong> {</pre><pre>let allUrls <strong>=</strong> <strong>await</strong> ShortUrl<strong>.</strong>find()</pre><pre><strong>return</strong> <strong>await</strong> <strong>h.</strong>view(&#39;index&#39;, { <em>allUrls</em>: allUrls })</pre><pre>}</pre><pre>});<br>...</pre><p>Making changes in the index route ‘/’ handler of the application.</p><pre>let allUrls = await ShortUrl.find()</pre><p>Here ‘allUrls’ returns all the URLs data from the DB.</p><pre>return await h.view(&#39;index&#39;, { allUrls: allUrls })</pre><p>h.view renders a template, the variable allUrls is passed to the template ‘index.ejs’ to render. The <em>{ allUrls: allUrls}</em> can be confusing, but it only passes allUrls as allUrls to the template index.ejs. So that it can be manipulated to render data in index.ejs.</p><p><strong>views/index.ejs</strong></p><pre>&lt;tbody&gt;</pre><pre><strong>&lt;%</strong> <strong>for</strong>(let i <strong>=</strong> 0; i <strong>&lt;</strong> allUrls<strong>.</strong>length; i<strong>++</strong>){<strong>%&gt;</strong></pre><pre>&lt;tr&gt;</pre><pre>&lt;td&gt;</pre><pre><strong>&lt;%</strong> <strong>if</strong>(allUrls[i]<strong>.</strong><em>fullUrl</em><strong>.</strong>length <strong>&gt;</strong> 50){ <strong>%&gt;</strong></pre><pre>&lt;a <em>href</em>=&quot;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>fullUrl</em><strong>%&gt;</strong>&quot; <em>target</em>=&quot;_blank&quot;&gt;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>fullUrl</em><strong>.</strong>slice(0,50)<strong>+</strong>&quot;...&quot;<strong>%&gt;</strong>&lt;/a&gt;</pre><pre><strong>&lt;%</strong> }<strong>else</strong>{ <strong>%&gt;</strong></pre><pre>&lt;a <em>href</em>=&quot;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>fullUrl</em><strong>%&gt;</strong>&quot; <em>target</em>=&quot;_blank&quot;&gt;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>fullUrl</em><strong>%&gt;</strong>&lt;/a&gt;</pre><pre><strong>&lt;%</strong>} <strong>%&gt;</strong></pre><pre>&lt;/td&gt;</pre><pre>&lt;td&gt;</pre><pre>&lt;a <em>href</em>=&quot;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>shortUrl</em><strong>%&gt;</strong>&quot; <em>target</em>=&quot;_blank&quot;&gt;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>shortUrl</em><strong>%&gt;</strong>&lt;/a&gt;</pre><pre>&lt;/td&gt;</pre><pre>&lt;td&gt;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>count</em> <strong>%&gt;</strong> &lt;/td&gt;</pre><pre>&lt;/tr&gt;</pre><pre><strong>&lt;%</strong>} <strong>%&gt;</strong></pre><pre>&lt;/tbody&gt;</pre><p>To display all the long URLs, short URLs, and count(number of times the link has been clicked). We will iterate through the ‘<em>allUrls</em>’ array. Using ‘<em>ejs’</em> template tags it makes it easy to get the required data from the iterable array object.</p><p>Inside the for loop, you could see an ‘<em>if else’ </em>block. This block limits the long URL string to not display more than 50 characters.</p><p><strong>Now,</strong> we are able to submit a long URL to our database and simultaneously generate a short URL and store it.</p><h4>How do we use this short URL to redirect?</h4><p><strong>views/index.ejs</strong></p><pre>...<br>&lt;a <em>href</em>=&quot;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>shortUrl</em><strong>%&gt;</strong>&quot; <em>target</em>=&quot;_blank&quot;&gt;<strong>&lt;%=</strong> allUrls[i]<strong>.</strong><em>shortUrl</em><strong>%&gt;</strong>&lt;/a&gt;<br>...</pre><p>As you can see the above line will generate a hyperlink for us. On clicking on it, it will make a <strong>GET </strong>request <em>“domain.xyz/shortstring”.</em></p><p>To give a clear picture lets see an example.</p><p>The above line of HTML code could be rendered as below.</p><p>&lt;a href=”<a href="https://secure-brook-45409.herokuapp.com/ByZ0q6tm">ByZ0q6tm</a>” target=”_blank”&gt;ByZ0q6tm&lt;/a&gt;</p><p>Where <strong>ByZ0q6tm</strong> is the short string. So when you click on the link. It makes a <strong>GET</strong> request “domain.xyz/ByZ0q6tm”.</p><p>To handle this <strong>GET</strong> request, we write the following logic in our controller.</p><p><strong>app.js</strong></p><pre>...</pre><pre>server<strong>.</strong>route({</pre><pre>method: &#39;GET&#39;,</pre><pre>path: &#39;/{shortUrl}&#39;,</pre><pre>handler: <em>async</em> (<strong>request</strong>, <strong>h</strong>) <strong>=&gt;</strong> {</pre><pre>let params_url <strong>=</strong> request<strong>.</strong><em>params</em><strong>.</strong><em>shortUrl</em></pre><pre>const shortUrl <strong>=</strong> <strong>await</strong> ShortUrl<strong>.</strong>findOne({ shortUrl: params_url });</pre><pre><em>//short url is not found</em></pre><pre><strong>if</strong>(<strong>!</strong>shortUrl){</pre><pre><strong>return</strong> <strong>await</strong> h<strong>.</strong>redirect(&#39;/&#39;)</pre><pre>}</pre><pre>shortUrl<strong>.</strong><em>count</em><strong>++</strong>;</pre><pre>shortUrl<strong>.</strong>save()</pre><pre><strong>return</strong> <strong>await</strong> h<strong>.</strong>redirect(shortUrl<strong>.</strong><em>fullUrl</em>)</pre><pre>}</pre><pre>})</pre><pre>...</pre><p>Here we are defining our path as path: ‘/{shortUrl}’. The purpose of doing so is to handle any <strong>GET </strong>request that has the URL ‘<em>domain.xyz/randomstring’.</em></p><pre>let params_url <strong>=</strong> request<strong>.</strong><em>params</em><strong>.</strong><em>shortUrl</em></pre><p>Here, the short URL is captured from the request parameter using the built-in API and stored in the ‘<em>params_url’ </em>variable.</p><pre>const shortUrl <strong>=</strong> <strong>await</strong> ShortUrl<strong>.</strong>findOne({ shortUrl: params_url });</pre><p>Here, we are finding the document by the <em>‘params_url’ </em>variable.</p><p>If we do not find it, we are redirecting it to the index page. If we find it, we are incrementing the count by 1, saving it and redirecting to the full long URL.</p><p><strong>Conclusion.</strong></p><p>Here we conclude building our URL shortener app. This sums up the explanation of the code. I hope I was able to simplify things and give you an overview of this lightweight microframework ‘<em>hapi.js</em>’.</p><p><a href="https://github.com/SaurabhPanja/url-shortener-hapi">Do check out the Github repository.</a></p><p><a href="https://github.com/SaurabhPanja/url-shortener-hapi">https://github.com/SaurabhPanja/url-shortener-hapi</a></p><p>This is how my version of the app looks like.</p><figure><img alt="Image of my application hosted on heroku." src="https://cdn-images-1.medium.com/max/1024/1*9YtOkocPdFggsDsAMsQNDg.png" /></figure><p><strong>*</strong><a href="https://secure-brook-45409.herokuapp.com/">Link to the application</a><strong> </strong><em>**</em></p><p><a href="https://secure-brook-45409.herokuapp.com/">URl Shortner | Hapi js</a></p><p><em>**This application was inspired by a video tutorial by one of my favorite javascript instructors, </em><strong><em>Kyle </em></strong><em>from </em><strong><em>Web Dev Simplified. </em></strong><em>Do check out his channel if you are into web development.**</em></p><p><strong>Web Dev Simplified Youtube Channel link: </strong><a href="https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw">https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw</a></p><p>If you want to build the same application in “<em>express.js”. Follow this video tutorial by </em><strong><em>Kyle.</em></strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSLpUKAGnm-g%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSLpUKAGnm-g&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSLpUKAGnm-g%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bc7192ba569ca927f1da4fd2f2a87ce/href">https://medium.com/media/7bc7192ba569ca927f1da4fd2f2a87ce/href</a></iframe><p>Thanks for reading till the end.</p><p>Have a good day. 😊</p><p>Saurabh Panja.</p><p><a href="https://saurabhpanja.com/">https://saurabhpanja.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18bfa3044e6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn to build a chrome extension to browse Instagram profiles without logging in.]]></title>
            <link>https://medium.com/@panjasaurabh/learn-to-build-a-chrome-extension-to-browse-instagram-profiles-without-logging-in-afda8b29177b?source=rss-f58c5461d9ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/afda8b29177b</guid>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[instagram]]></category>
            <category><![CDATA[learn]]></category>
            <category><![CDATA[instagram-login]]></category>
            <dc:creator><![CDATA[Saurabh Panja]]></dc:creator>
            <pubDate>Mon, 30 Dec 2019 17:24:21 GMT</pubDate>
            <atom:updated>2020-01-19T07:11:55.678Z</atom:updated>
            <content:encoded><![CDATA[<p>So here is the problem, every time I want to browse an Instagram profile, as soon as I scroll down I am asked to log in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KduNT4YTh8oLs5mMKNgjbg.png" /><figcaption>Forced log in pop up!</figcaption></figure><p>I don’t want to do it. So I figured out a way to hidethe login pop up, by building a chrome extension to do it for me.</p><h4>Let’s get started</h4><p>1. Create a directory</p><p>2. Create two files that you are going to need, i.e. <em>“manifest.json”,” main.js”</em></p><blockquote><em>manifest.json</em></blockquote><pre>{</pre><pre>&quot;name&quot;: &quot;Insta No Login&quot;,</pre><pre>&quot;version&quot;: &quot;1.0&quot;,</pre><pre>&quot;description&quot;: &quot;Browse Instagram without logging in&quot;,</pre><pre>&quot;manifest_version&quot;: 2,</pre><pre>&quot;content_scripts&quot;: [</pre><pre>{</pre><pre>&quot;matches&quot;: [&quot;https://*.instagram.com/*&quot;],</pre><pre>&quot;js&quot;: [&quot;main.js&quot;]</pre><pre>}</pre><pre>]<br>}</pre><p>The file manifest.json is pretty much self-explanatory. Do not forget to set</p><pre>&quot;manifest_version”: 2</pre><p>content_script is the most important block in our manifest.json. We are building a chrome extension that will manipulate the DOM.</p><pre>&quot;content_scripts&quot;: [</pre><pre>{</pre><pre>&quot;matches&quot;: [&quot;https://*.instagram.com/*&quot;],</pre><pre>&quot;js&quot;: [&quot;main.js&quot;]</pre><pre>}</pre><pre>]</pre><p>Whenever a URL matches with <a href="https://*.instagram.com/*">https://*.instagram.com/*</a> our extension will be activated.</p><p>All the DOM manipulation will be written inside the main.js file.</p><blockquote>main.js</blockquote><pre>window<strong>.</strong>onload <strong>=</strong> () <strong>=&gt;</strong> {</pre><pre>let body <strong>=</strong> document<strong>.</strong>querySelector(&quot;body&quot;);</pre><pre>body<strong>.</strong><em>style</em><strong>.</strong><em>overflow</em> <strong>=</strong> &quot;&quot;;</pre><pre>body<strong>.</strong>addEventListener(&quot;click&quot;, removeLoginBox)</pre><pre>}</pre><pre>const removeLoginBox <strong>=</strong> () <strong>=&gt;</strong> {</pre><pre>let body <strong>=</strong> document<strong>.</strong>querySelector(&quot;body&quot;);</pre><pre>body<strong>.</strong><em>style</em><strong>.</strong><em>overflow</em> <strong>=</strong> &quot;&quot;;</pre><pre>let loginBox <strong>=</strong> document<strong>.</strong>querySelector(&quot;.RnEpo.Yx5HN&quot;);<br>//loginBox class</pre><pre><strong>if</strong> (loginBox) {</pre><pre>loginBox<strong>.</strong><em>style</em><strong>.</strong><em>display</em> <strong>=</strong> &quot;none&quot;</pre><pre>}</pre><pre>}</pre><p>The logic behind removing the login pop up is quite simple.</p><p>As soon as the login box appears and asks us to log in. We will add an event listener to the body. So that on clicking anywhere on the html body, our function to hide the login box is called and executed.</p><p>Simple logic, isn’t it?</p><p><strong>Link to GitHub Repo</strong></p><blockquote><a href="https://github.com/SaurabhPanja/insta_no_login_extension">https://github.com/SaurabhPanja/insta_no_login_extension</a></blockquote><p>Now to add this to chrome and test it, follow this article.</p><p><a href="https://webkul.com/blog/how-to-install-the-unpacked-extension-in-chrome/">How to install the unpacked extension in Chrome - Webkul Blog</a></p><p>Well, that‘s it. I hope this fun little example will give you an overview how to build a chrome extension to manipulate DOM.</p><p>Thanks.</p><p><a href="https://saurabhpanja.com/">https://saurabhpanja.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afda8b29177b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>