<?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"><channel><title><![CDATA[Haseeb Elahi's Blog]]></title><description><![CDATA[Software engineer at Conrad Labs, a launchpad for startups mainly based in Austin, TX. I usually work full stack on some cool web & cloud-based products!]]></description><link>https://blog.haseebelahi.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 05:53:02 GMT</lastBuildDate><atom:link href="https://blog.haseebelahi.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding PWAs - Exploring the Twitter PWA with Dev Tools]]></title><description><![CDATA[PWAs (Progressive Web Apps) have been around for quite some time now. With time the PWA developer ecosystem and browser support has become mature and most of the top web platforms are now starting to add PWA support to their web apps. So what exactly...]]></description><link>https://blog.haseebelahi.dev/understanding-pwas-exploring-the-twitter-pwa-with-dev-tools</link><guid isPermaLink="true">https://blog.haseebelahi.dev/understanding-pwas-exploring-the-twitter-pwa-with-dev-tools</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[PWA]]></category><category><![CDATA[Twitter]]></category><category><![CDATA[HTML5]]></category><dc:creator><![CDATA[Haseeb Elahi]]></dc:creator><pubDate>Mon, 12 Apr 2021 17:26:38 GMT</pubDate><content:encoded><![CDATA[<p><strong>PWAs (Progressive Web Apps)</strong> have been around for quite some time now. With time the PWA developer ecosystem and browser support has become mature and most of the top web platforms are now starting to add PWA support to their web apps. So what exactly is a PWA?</p>
<p>MDN's under construction PWA <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps">page</a> defines a PWA as</p>
<blockquote>
<p>"Progressive Web Apps are web apps that use emerging web browser APIs and features along with traditional progressive enhancement strategy to bring a native app-like user experience to cross-platform web applications. Progressive Web Apps are a useful design pattern, though they aren't a formalized standard."</p>
</blockquote>
<p>If this definition is too vague or broad for you, you can safely assume that PWAs are web apps which run in the browser but can be "installed" on the user's smartphone or computer to provide a native app like behavior but in the browser. Generally, some offline functionality or graceful application behavior without network connectivity is expected from PWAs.</p>
<p>To better understand how PWAs are implemented and what better experience this web application design pattern provides, let's try to dig into and reverse engineer the Twitter PWA using the Chrome Dev Tools.</p>
<h2 id="the-manifest">The Manifest 📜</h2>
<p>If your web app is going to be "installed" it needs to have some metadata, e.g the app's name, icons for different resolutions and a url to which the app opens to by default. All of this information is added in a json file present at the <code>/manifest.json</code> path.</p>
<p>Here is a screenshot of the Twitter's <code>manifest.json</code> file. 
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb2cv1zguuesp4waft4z.png" alt="Screenshot of Twitter PWA manifest.json file" />
You can see the detail you can provide and the support for the possible interoperability of the Twitter Android native and the PWA app using the <code>android_package_name</code> property. Pretty powerful and feature rich!
Read more about the manifest file and what it can support <a target="_blank" href="https://web.dev/add-manifest/">here</a>.</p>
<h2 id="service-worker">Service Worker 🧑‍🏭</h2>
<p>The ❤️ of PWA - <code>service worker</code> is a JS script that lives separate from the browser page. Among other features, it provides a <em>network proxy</em> for the web page it is running for. This means every network request originating from that page passes through the <code>service worker</code>. This opens up possibilities and provides more control over resource caching, offline application behavior and requests for resources or API calls that are sent to the server. </p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppwrxdqpinwbdvzm6al3.png" alt="Twitter Service Worker Chrome Dev Tools Screenshot" /></p>
<p>The Twitter <code>service worker</code> is registered under the <code>https://twitter.com/</code> path which means it will work as <code>service worker</code> for all paths under the <code>twitter.com</code> host. Service workers once installed against a web app keep running even when you navigate away from the page and become active every time user goes to the URL for which a <code>service worker</code> is registered in the browser. Read more about the lifecycle, features and nuances of service workers <a target="_blank" href="https://developers.google.com/web/fundamentals/primers/service-workers">here</a>.</p>
<h2 id="cache-storage">Cache Storage 🛍️</h2>
<p>The <code>Cache Storage</code> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage">Web API</a> provides a simple way to implement caching of resources in the browser. It is important not to confuse this API with the default browser caching implemented by default.
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afpc9unsncwysf6mpmye.png" alt="Twitter Cache Storage Chrome Dev Tools Screenshot" /></p>
<p>As you can see there is a list of js files stored in the cache storage and each one of them has a path in the <code>name</code> field. Remember when we said that the <code>service worker</code> acts as a network proxy for the page. This means every request for these js resources originating from <code>twitter.com</code> first passes through the <code>service worker</code>. </p>
<p>The <code>service worker</code> is implemented in such a way that for every resource request it first checks if the resource is present in the cache storage. If it is, the page is sent a <code>200 OK</code> response along with the required resource, without ever hitting the <code>twitter.com</code> servers. You can see a live demo of it in the Network console.
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kruzgw2nqvtr1foed6n7.png" alt="Network Tab screenshot for twitter.com" />
As you can see in this screenshot, for the js resource <code>bundle.HomeTimeline...js</code> the request never hits the servers and the <code>twitter.com</code> page still gets the <code>200 OK</code> response along with the script.</p>
<p>Similarly, the HTML skeleton/shell of the Twitter app is also cached.</p>
<p>Even if there is no internet connection, the Twitter web app's HTML and JS will be served to the page from the <code>Cache Storage</code> by the <code>Service Worker</code>, making the app resilient to slow or no internet connectivity.</p>
<h2 id="indexeddb">IndexedDB 💾</h2>
<p>Another one of the emerging web browser API that PWAs use is the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API">IndexedDB API</a>. The IndexedDB is an interface for storing and accessing structured data within the browser. </p>
<p>Twitter makes interesting use of this feature for optimizing user experience by storing different kinds of less frequently changing metadata for the logged in user and some recent user activity so that it can be fetched directly from within the browser when needed.
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/waoztkevjc1v84y7ibdg.png" alt="Twitter IndexedDB Chrome Devtools screenshot" />
A quick look under the <code>IndexedDB</code> category for <code>twitter.com</code> shows multiple IndexedDB instances, some with only a single Object store, some with multiple.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f742kprnail04edj3vrn.png" alt="Twitter IndexedDB Chrome Devtools screenshot" /></p>
<p>Expanding in and looking at the contents of one of the DBs with an object store called <code>keyvaluepairs</code> we can see that it has stored a list of my recently used emojis on Twitter.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msfsoo04rvf98zxhtjfy.png" alt="Twitter IndexedDB Chrome Devtools screenshot" /></p>
<p>The Object store in the DB with the identifier <code>localforge</code> contains some more metadata about the user.</p>
<p>This kind of data could have been stored using good old <code>Local Storage</code> but newer features like <code>IndexedDB</code> are meant to server as an objectstore database for your application right within the browser.</p>
<h2 id="installing-the-twitter-pwa">Installing the Twitter PWA ⬇️</h2>
<p>You can use a little button in the Chrome browser URL field to install the PWA as an app.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ro3jge6heent87lrq4b.png" alt="Twitter PWA installation Screenshot" /></p>
<p>Once installed, you now have a Twitter app icon in your dock/task bar and the app opens in a separate window different from your browser.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsk92ctpbl7yy6pkfozu.png" alt="Twitter PWA installed" /></p>
<h2 id="the-offline-test">The Offline Test 🚫</h2>
<p>Let's see what happens if I turn off my network and try opening the newly installed Twitter PWA. </p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzr6o5swxr6jrzlyugdd.gif" alt="Gif showing the behavior of Twitter PWA when offline" /></p>
<p>As you can see, the app's UI gets loaded. Most of the navigations work, but no tweets or trends data is loaded. It is <strong>important</strong> to understand:</p>
<ul>
<li>The UI works because the app's HTML and CSS are in <code>Cache Store</code> and are being served through the <code>service worker</code></li>
<li>The interactions and navigations work because the JS implementing those is also stored in <code>Cache Store</code>.</li>
<li>The profile page shows some of the user metadata, which means that data is stored somewhere maybe in the IndexedDB from which the app is fetching it rather than the API.</li>
<li>As the installed Twitter app is actually only a separate Chrome instance which only goes to <code>https://twitter.com</code>, but we are not seeing the 'No Internet Connection' page with a trex because the <code>Service Worker</code> is acting as a <em>network proxy</em> and still serving content and responding to the network requests of the <code>twitter.com</code> page even without a connection to the Twitter servers.</li>
</ul>
<p><em>Phew you reached the end! Hopefully, you learned something new. If you want to ask a question, leave your thoughts about PWAs or you think there's a mistake in the article above, I'll be glad to hear from you in the comments below. You can also reach out to me on Twitter <a target="_blank" href="https://twitter.com/haseebelaahi">@haseebelaahi</a></em> 🙂</p>
]]></content:encoded></item><item><title><![CDATA[What I Found When I Went Through My Facebook Location Data]]></title><description><![CDATA[For some time Facebook has been allowing users to download the data it has on them, so one curious night I went ahead and downloaded all of my location data that Facebook has.
Screen Capture: Facebook, Download Your Information Page
Facebook allows y...]]></description><link>https://blog.haseebelahi.dev/what-i-found-when-i-went-through-my-facebook-location-data</link><guid isPermaLink="true">https://blog.haseebelahi.dev/what-i-found-when-i-went-through-my-facebook-location-data</guid><category><![CDATA[Facebook]]></category><category><![CDATA[Security]]></category><category><![CDATA[#data visualisation]]></category><category><![CDATA[Python]]></category><category><![CDATA[python projects]]></category><dc:creator><![CDATA[Haseeb Elahi]]></dc:creator><pubDate>Sun, 11 Apr 2021 07:20:30 GMT</pubDate><content:encoded><![CDATA[<p>For some time Facebook has been allowing users to download the data it has on them, so one curious night I went ahead and downloaded all of my location data that Facebook has.</p>
<p><img src="https://cdn-images-1.medium.com/max/1024/1*tkbyxMYY69-yfg3rVlc6bQ.png" alt /></p>Screen Capture: Facebook, Download Your Information Page<p></p>
<p>Facebook allows you to download your data as browser viewable HTML, but that view isn’t really interesting and doesn’t reveal much (as Facebook would probably want 🤷‍♂️). The HTML view just gives you a boring list of coordinates like this.</p>
<p><img src="https://cdn-images-1.medium.com/max/1024/1*soQh7xPvDrB0k_uONdzFkA.png" alt /></p>Screen Capture: Facebook User Location Data<p></p>
<p>I downloaded the data in JSON which is another of the supported formats and did some basic stats &amp; visualizations.</p>
<p><em>I have been a Facebook user since 2011 but started using the Facebook app on my phone 3–4 years later. All of the stats and visualizations here are from location data ranging from January 2015–April 2019.</em></p>
<h3 id="number-of-times-facebook-stored-my-location"><strong>Number of Times Facebook Stored My Location</strong></h3>
<p>Facebook accessed and stored my location for a total of <strong>2818</strong> times in the period from <em>start of 2015 to April of 2019</em> averaging almost <strong>650 times a year</strong> , <strong>54 times a month</strong> 🙀 or <strong>twice every day</strong> 😮. When you think about these numbers for a moment, it almost feels like basically being tracked literally all the time!</p>
<h3 id="stored-locations-by-year">Stored Locations By Year</h3>
<p>Facebook’s location collection seems to be tied with how often your location changes and obviously having your phone’s location turned on is a prerequisite. This graph shows a trend of location entries by each year.</p>
<p><img src="https://cdn-images-1.medium.com/max/1024/1*AYEVAoQwzEWa583w2c7ODQ.png" alt /></p>My location data on Facebook by year<p></p>
<p>The reason for the huge spike in data collection from 2016 to 2017 is maybe due to some change in Facebook’s location collection policy or probably I just bought a good smartphone in 2017 and started having the location turned on all the time on my Android smartphone.</p>
<h3 id="busiest-location-collection-days"><strong>Busiest Location Collection Days</strong></h3>
<p>Digging deeper into the data, I went ahead and filtered out the ten days which had the highest location collection frequency. Can you guess how many times at maximum my location got stored on Facebook on any given day?</p>
<p>50, 100? Nope, <strong>Two Hundred and Thirty-Eight</strong> times!</p>
<p><img src="https://cdn-images-1.medium.com/max/1024/1*eXbaCvvNeb6LhsaQuB6q8w.png" alt /></p>Top 10 Highest Location Collection Days<p></p>
<p>Turns out I was traveling on that particular day and was on the road for the most part of my day and Facebook like any worried parent would do, checked on me for <strong>238</strong>  times…</p>
<h3 id="what-would-all-of-this-data-look-like-on-a-map"><strong>What would all of this data look like on a map?</strong></h3>
<p>Naturally I wanted to put all of this latitude and longitude data on an actual map to visualize where I have been moving around in all these years!</p>
<p><img src="https://cdn-images-1.medium.com/max/1024/1*rrsvxcDsEtK1h0kK359tFA.png" alt /></p>My location data from Facebook on my hometown’s map<p></p>
<p>So this above is a visual representation of my location data that Facebook has almost in a 15km radius of my house in my hometown (Lahore, PK). Each blue dot represents one instance of a location captured and stored by Facebook.</p>
<p>For some of the locations marked here I didn’t even remember visiting that area but thanks to Facebook for providing hard evidence I recalled <strong><em>everywhere I’ve been in the past 4 years </em></strong> 🙃</p>
<p>With the location data, timings for each location capture and Facebook’s resources it is very easy to infer any Facebook app user’s home address, workplace, where do they go on weekends regularly, which restaurants they eat at and so on. <strong><em>All of this definitely makes targeting ads easier and of course classifying specific user personas for political and social purposes</em></strong>.</p>
<p>Considering the latest speculation about Facebook launching a dating service of their own, this data could be of a lot more use in <em>“</em>👫 <em>bringing people together”!</em></p>
<p>So, next time when you meet someone and the next thing is that they start appearing in your ‘<em>Suggested Friends</em>’ list don’t get surprised 😆</p>
<p>You can find detailed analysis on my Facebook data here on Kaggle</p>
<p><a target="_blank" href="https://www.kaggle.com/helahi/facebook-messages-analysis">https://www.kaggle.com/helahi/facebook-messages-analysis</a></p>
<p><em>Thank you for making it through! If you think I should dig in some more into this data to find any other stats or patterns, let me know in the comments or get in touch with me on Twitter <a target="_blank" href="https://twitter.com/haseebelaahi">@haseebelaahi</a>!</em> </p>
]]></content:encoded></item></channel></rss>