<?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 Gokul Kathirvel on Medium]]></title>
        <description><![CDATA[Stories by Gokul Kathirvel on Medium]]></description>
        <link>https://medium.com/@gokatz?source=rss-7a1aeba9bdb2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0I9m-BINnjyycQr0F6j1aA.png</url>
            <title>Stories by Gokul Kathirvel on Medium</title>
            <link>https://medium.com/@gokatz?source=rss-7a1aeba9bdb2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:17:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gokatz/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[My Intro to Chrome Extension Development — A Series]]></title>
            <link>https://gokatz.medium.com/my-intro-to-chrome-extension-development-a-series-6544f52634c5?source=rss-7a1aeba9bdb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6544f52634c5</guid>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[extension]]></category>
            <dc:creator><![CDATA[Gokul Kathirvel]]></dc:creator>
            <pubDate>Thu, 21 Oct 2021 03:32:09 GMT</pubDate>
            <atom:updated>2021-10-21T03:32:09.764Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Intro to Chrome Extension Development — A Series</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hP4KhrjAmP_lINXp.jpg" /></figure><p><em>[Image from From </em><a href="https://www.pexels.com/photo/macbook-air-on-grey-wooden-table-67112/"><em>pexels.com</em></a><em>]</em></p><p>Building a chrome extension is definitely a fun process! Chrome extensions open a whole new set of doors to the web developers and users as well.</p><p>That is the reason I’m planning this to be a series of blogs explaining in-depth about the chrome extension ecosystem and the development, testing, and deployment process. This is the first part which explains what are chrome extensions and a brief about other browser ecosystems.</p><h3>What are Chrome Extensions?</h3><p>As per the official <a href="https://developer.chrome.com/docs/extensions/">chrome extension development guide</a>, the definition for a chrome extension would be:</p><blockquote><em>Extensions are software programs, built on web technologies (such as HTML, CSS, and JavaScript) that enable users to customize the Chrome browsing experience.</em></blockquote><p>This definition is self-explanatory, right? However, I would put it in a slightly different way:</p><p><em>Extensions are used to </em><strong><em>enhance the browsing experience</em></strong><em> using the customization feature enabled by the browsers via various APIs</em></p><p>These customization ranges from changing a content, <a href="https://chrome.google.com/webstore/detail/dark-mode/dmghijelimhndkbmpgbldicpogfkceaj?hl=en">look and feel</a> inside a webpage, <a href="https://chrome.google.com/webstore/detail/grammarly-for-chrome/kbfnbcaeplbcioakkpcpgfkobkghlhen?hl=en">injecting a widget</a> into the page and all the way to <a href="https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?hl=en">intercept the network request</a> and change its behavior and content. The possibility is <strong>limitless</strong>.</p><h3>A little history</h3><p>The extension architecture we are using today is a modern take by the web browser vendors to extend the browse functionality. Before the current extension architecture, we had plugin architecture using API surfaces like <a href="https://en.wikipedia.org/wiki/NPAPI">NPAPI</a>, etc., You might have heard about the recently <a href="https://www.adobe.com/in/products/flashplayer/end-of-life.html">deprecated Adobe flash plugin</a> for the browsers. This is a classic example of plugin software.</p><p>Due to various limitations and issues such as security (No Sandboxing), stability, etc. browser vendors decided to deprecate the plugin ecosystem and come up with the now existing, browser extension architecture built using the existing web technologies.</p><h3>Is it worth our time?</h3><p>We might have heard about/used extensions that are fun to use and concise in functionality. However, the possibility is not so concise and companies around the globe are making use of this technology to improve the product experience and drive a lot more customers towards their brand/site. For instance, for a business like password managers/vault-like, <a href="https://www.zoho.com/vault">Zoho Vault</a> (I worked here 😉), <a href="https://www.lastpass.com/">LastKeep</a>, etc., browser extensions are not an optional one. They had to have an extension to work seamlessly and it drives a major part of the user experience and of course, in turn, revenue.</p><p>Hence, depending upon our use case/business model, the knowledge about chrome extensions and it’s development might be crucial and of course, there is always fun tweaking the browser behavior, right? 😉</p><h3>How to build one?</h3><p>We’ve seen a brief intro about the extension and its ecosystem. Let’s dive into the actual chrome extension development process. The chrome extension development history has seen a lot of phases and the process we are following today is a result of the refinement of those phases. In the modern era, we can develop a chrome extension by using the web technologies we are familiar with, <strong>HTML, CSS, and JavaScript</strong> with the help of a <strong>bunch of browser APIs</strong> exposed by Chrome to access the internals of the browser itself. These APIs are the ones that help us to build the enhanced experience.</p><p>A-lot-simplified architecture would be something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G8b_YVvNMBFDn3EB.png" /></figure><h3>The Standard</h3><p>The development story of the extension had been coupled to individual browser vendors. Each vendor devised their own way to develop and package an extension for their browser software. This causes a lot of roadblocks for developers to build their extensions across multiple browser vendors. To solve this and to make the development process close to today’s web developers, initially, Mozilla joined hands with Microsoft and Opera to come up with the initial draft. The spec closely resembles the APIs devised by Chrome for their extensions.</p><p>Unfortunately, lately, the spec has had no traction and dormant for some time. Let’s hope the work will be resumed in near future in this space 🤞</p><p>The spec draft can be found here: <a href="https://browserext.github.io/browserext/">https://browserext.github.io/browserext/</a></p><h3>Why Just Chrome?</h3><p>As we can see, browser vendors are more keen to unify the extension development process so that the extension will work cross-browser. Then, it will be a natural question, then why should we just learn about Chrome extension and not a genetic development process.</p><p>The main reason is that the web extension spec has still a long way to rely on and they are heavily inspired by Chrome’s API. So,</p><ul><li>we are gonna focus on building chrome extension as the skills are transferable to any browser vendors</li><li>We are gonna learn how to port a chrome extension into other browsers at the end of this series as well.</li></ul><p>So, stay tuned (<em>You can </em><strong><em>subscribe </em></strong><em>using the below form </em>👇<em> to get alert when I publish the next part</em>). We gonna explore a lot about chrome extensions and the relevant ecosystem. Until then, see you all 👋👋</p><p><em>Originally published at </em><a href="https://www.gokatz.me/blog/chrome-extension-intro-part-1/"><em>https://www.gokatz.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6544f52634c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the UI Testing of your chrome extension]]></title>
            <link>https://gokatz.medium.com/automate-the-ui-testing-of-your-chrome-extension-ac16a35021db?source=rss-7a1aeba9bdb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac16a35021db</guid>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[mocha]]></category>
            <dc:creator><![CDATA[Gokul Kathirvel]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 09:25:42 GMT</pubDate>
            <atom:updated>2021-01-02T05:15:05.081Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Atwv-qjtU6YRDyP3Nh-sZQ.jpeg" /><figcaption>From Unsplash (<a href="https://unsplash.com/photos/ky0ljKGar78">https://unsplash.com/photos/ky0ljKGar78</a>) by <a href="https://unsplash.com/@kundeleknabiegunie">@kundeleknabiegunie</a></figcaption></figure><p>👉<em> Originally published on </em><a href="https://gokatz.me/blog/automate-chrome-extension-testing/"><em>gokatz.me</em></a><em>. Follow here for regular updates and more on chrome extensions — </em><a href="https://gokatz.me/blog/automate-chrome-extension-testing/">https://gokatz.me/blog/automate-chrome-extension-testing/</a></p><h3>Automate the UI Testing of your chrome extension</h3><p>Building a chrome extension is definitely a fun process! Chrome extensions open a whole new set of doors to the web developers and users. However, testing those awesome extensions is not as straight forward as testing any conventional web application in some aspects. In this post, Let’s walk together with the path of adding our first test case that ensures the best for our extensions.</p><h3>Why automate on the first place</h3><p>The manual testing process is one of the boring stuff in Software Engineering 😆 With the various aspects such as <strong>new install</strong>, <strong>extension update</strong>, <strong>permission update</strong>, <strong>extension downgrade/delete</strong> of the Chrome extension, the process got a lot trickier and bored. It’s really easier to miss testing few aspects on every release. Thus, automating these boring stuff can ensure the proper working of our extension during every single release.</p><h3>How testing can be done</h3><p>We will be testing a chrome extension using <strong>Puppeteer</strong> and structure our tests with the <strong>mocha</strong> test runner. Also, we’ll see how to automate this testing process in your CI/CD process using <strong>CircleCI</strong>. You can use any of your favorite test runner and CI/CD tool.</p><p>Let’s install our dependencies first,</p><p>yarn add puppeteer mocha -D or npm i puppeteer mocha --dev</p><p>We can test our chrome extensions with the help of Puppeteer by mimicking the steps we would follow in our manual testing process.</p><ul><li>Open Chrome Browser</li><li>Load the unpacked version of the extension (via chrome://extensions page - dev mode)</li><li>Open our extension popup/index page</li><li>Test the targeted features</li></ul><p>Let’s automate those steps one by one. For better understanding, Kindly test the script we are building at each step by running them ( node test.js) then and there.</p><h3>Step 1: Open Chrome Programmatically</h3><p>As a first step, we need to control Chrome programmatically. That exactly where <em>Puppeteer</em> helps us. As per the docs, Puppeteer is a <strong>Node library which provides a high-level API to control headless (and full non-headless) Chrome</strong>. In our case, we need to boot Chrome in <strong>full form</strong> as extensions can load only in full form.</p><p>On running the script ( node test.js), The chromium build will be boot up with an empty page. Kill the node process to close the Chromium browser.</p><h3>Step 2: Load Extensions</h3><p>Next up, need to load our extension into chrome. Extensions can be load into the browser instance using --load-extension flag given by Puppeteer. Additionally, we need to disable all other extensions to prevent any unnecessary noise using a flag, --disable-extensions-except.</p><p>On running this script, Chrome instance will be booted along with your extension. You can find your extension logo on the toolbar menu.</p><h3>Step 3: Go to the extension popup page</h3><p>Extension popup/index page will open when we click on the extension icon in the toolbar menu. The same page can be opened directly using the chrome-extension URL for the easier testing process. A normal extension page URL will be like chrome-extension://qwertyasdfgzxcvbniuqwiugiqwdv/index.html. This URL can be dissected into,</p><ul><li>Extension Protocol (chrome-extension)</li><li>Extension ID (qwertyasdfgzxcvbniuqwiugiqwdv)</li><li>Popup/Index page path (index.html)</li></ul><p>We need to construct this kind of URL for our extension in order to visit the page. Here the unknown part is the <strong>Extension ID.</strong> Thus, we need to know the arbitrary ID of our the extension generated by Chrome.</p><h3>Know your extension ID: The Proper way</h3><p>Chrome will assign a unique extension ID to every extension when loaded. This will be random every time we boot the extension on a new Chrome instance. However, a stable extension ID specific for our extension can be set by following the steps mentioned in this <a href="https://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development/23877974#23877974">SO answer</a>. This will be a bit long process but fool-proof. We can safely rely on the stable ID to test our extensions as the ID will not change when booted in various Chrome instance using Puppeteer.</p><h3>Know your extension ID: The Background Script way</h3><p>However, if our extension got background scripts, then the process would be a bit straight forward. We can detect the Extension ID programmatically.</p><p>When using background scripts, Chrome will create a target for the background script as soon as the extension gets loaded ( <em>Step 2</em>). All the page targets managed by Chrome can be accessed by the targets method of the booted browser instance. using these targets, we can pull out our specific extension target with the help of title property (which will be our extension title given in the manifest.json). This target will contain the random extension ID assigned by Chrome during the current boot up.</p><p>Once you fetch your extension target, we can extract the ID from the target URL. A sample background target URL will be like, chrome-extension://qwertyasdfgzxcvbniuqwiugiqwdv/background.html. So, the extraction will be like:</p><p>We successfully got our extension ID (by either way) 💪</p><h3>En Route to the Extension page 🚌</h3><p>Now, let’s go to our extension page. For this, we need to create a new browser page and load the appropriate extension popup URL.</p><p>At this point, running the test script will boot up a new Chrome instance and open a new Page with your extension popup HTML page content as a usual web page.</p><h3>Step 4: Test the targeted features</h3><p>We have successfully booted up our extension page. It’s time for a 🖐</p><p>Now, let’s pour our web app testing knowledge here. As every web application, end-to-end testing can be done using DOM querying and asserting for the proper value. The same can be applied here. DOM of our extension page can be queried using the and APIs provided by Puppeteer. You can use your preferred assertion library. In this example, I’m using the node’s native package.</p><p>Events can be triggered on the extension page using various event APIs provided by the Puppeteer.</p><p><strong>NOTE:</strong> Puppeteer got a lot of useful <a href="https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md">APIs</a> to control and extract useful information from Chrome.</p><h3>Use test runners</h3><p>In order to patch tests in a meaningful manner and to get good visual feedback and, we can use a test runner. In this example, I’m going to demonstrate how to use to structure our tests.</p><h3>Joining all the pieces</h3><p>Let’s join all pieces to create a completely automated test suite for your extension.</p><p>we can run this script by invoking the mocha command.</p><p>let’s create an npm script in package.json to map the mocha command,</p><pre>&quot;scripts&quot;: { <br>  &quot;test&quot;: &quot;mocha test.js&quot; <br>}</pre><p>It would invoke the test and output the test case status in the terminal.</p><pre>$ yarn test <br>$ mocha test.js </pre><pre>Extension UI Testing Home Page <br>  ✓ Greet Message (142ms) 1 passing (5s)</pre><p>Congrats, You made far to the end 🤝</p><p>We have done creating our first test suites that test our extension page. It’s time to wire this up with a CI overflow. I’m using <strong>CircleCI</strong> for this demo. We can use any such services like <strong>TravisCI</strong>, <strong>AppVeyor</strong>, etc.,</p><h3>Wiring up with CI</h3><p>create a config file for <strong>CircleCI</strong>, .circleci/config.yml and load up a few boilerplate steps. We will be using an image called circleci/node:8.12.0-browsers as this image has chrome pre-installed and we need not install any further dependencies. If you are using any other services, find an appropriate image with browsers pre-built.</p><pre>version: 2<br>jobs:<br>  build:<br>    docker:<br>      - image: circleci/node:8.12.0-browsers</pre><pre>working_directory: ~/repo</pre><pre>steps:<br>      - checkout<br>      - restore_cache:<br>          keys:<br>          - v1-dependencies-{{ checksum &quot;package.json&quot; }}<br>          <br>          # fall back to using the latest cache if no exact match is found<br>          - v1-dependencies-</pre><pre># Install your dependencies<br>      - run: yarn install</pre><pre>- save_cache:<br>          paths:<br>            - node_modules<br>          key: v1-dependencies-{{ checksum &quot;package.json&quot; }}</pre><pre># build the extension if required<br>      # Run our test suite <br>      - run: yarn test</pre><p>Woohoo… Congrats again. We just automated our test process successfully 🔥🔥 Try to automate your existing and future extension’s testing process and be calm on your future releases. The sample extension along with their (working) tests has been hosted in <a href="https://github.com/gokatz/greet-me-extension">GitHub</a>. If you need any help, you can refer to the source code.</p><p>Hope you find this piece of writing useful. If so, I wrote about automating the chrome extension deployment in your CI/CD process in this <a href="https://gokatz.me/blog/automate-your-chrome-extension-deployment-in-minutes/">blog post</a>. Check out if you are manually deploying your extension. This may be the time to automate that too 😉</p><p>That’s all for today. Let’s meet at another time with some other exciting stuff. Bye for Now. If you got any feedback or suggestion, please post in the comment. I would love to work on that.</p><p><em>Originally published at </em><a href="https://gokatz.me/blog/automate-chrome-extension-testing/"><em>https://gokatz.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac16a35021db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NIL pattern #perfmatters]]></title>
            <link>https://gokatz.medium.com/nil-pattern-perfmatters-4fa13e96274d?source=rss-7a1aeba9bdb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fa13e96274d</guid>
            <category><![CDATA[emberjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[perfmatters]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Gokul Kathirvel]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 17:29:13 GMT</pubDate>
            <atom:updated>2018-08-03T02:18:12.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MqToD2juFmEx_rYb5yOKVQ.jpeg" /><figcaption>Cover image credit: <a href="https://unsplash.com/@marcojodoin"><em>Marc-Olivier Jodoin</em></a><em> from </em><a href="https://unsplash.com/"><em>unsplash.com</em></a></figcaption></figure><p><em>Originally published at </em><a href="https://dev.to/gokatz/nil-pattern-perfmatters-3jjh"><em>dev.to</em></a><em>.</em></p><p>While delivering content to our users via the internet, performance is one of the key checkboxes that need to be checked. Even though our content is awesome, we may face churns over our products if our site/app is not performing well. We need to <em>Start Fast! and Stay Fast!!</em> to grab and retain our user base.</p><p>There are a lot of awesome and clever techniques out there to improve the performance of our sites which includes <em>reducing the initial load, proper asset caching, prefetching critical resources, offloading heavy computation to workers etc.,</em></p><p>In this article, we are going to see another such technique that I inspired from a <a href="https://medium.com/u/ef81ef829bcb">Pinterest Engineering</a> blog about their <a href="https://medium.com/@Pinterest_Engineering/a-one-year-pwa-retrospective-f4a2f4129e05">one year PWA success story</a> by Zack Argyle . The entire post was a very neat narration of their journey. Definitely give it a try to know more about interesting data loading patterns.</p><p><strong>The idea taken from the post is as follow:</strong></p><blockquote>if you browse a feed of Pins, we have information about each Pin. When you tap on one, it takes you to a detailed view. Because the Pin data is normalized, we can easily show the limited details we have from the feed view until the full details finish being fetched from the server</blockquote><p>We might have cases in our application where we have a list of things to pick from a list and upon clicking an item, we should load the entire details of the item. That is where the NIL pattern <em>(expansion to be disclosed 😜)</em> will come into play. Take all the data available in the list view and put it on the details view when a user clicks on the particular item and fetch only the remaining details to be displayed on the details view while user digesting the displayed data.</p><p>Named the above-said pattern as <strong>Near Instant Loading (NIL)</strong> pattern 😉!</p><p>By implementing this, we can even entirely eliminate a loading spinner that splashes every-time the user click on the item. With this little perceived-performance improvement, the user might feel the page rendering as instant 💪</p><p>Following is an implementation of <em>NIL pattern</em> in an <a href="https://emberjs.com/">Ember.js</a> app and can be inherited to any frameworks.</p><p>Our sample application is a blog site which has a list of blogs posts. With an ordinary implementation, the site is something like 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*ZJFsx9-TCBoCffYK.gif" /><figcaption>Sample Application</figcaption></figure><p>We got that loading splash every-time we click on any post and have to wait for the data to load from the server. This loading time depends on various factors. To implement the NIL pattern, first, we need to eliminate the intermediate loading sub-state (the loading screen after clicking the post) and then pass the data from the list page to the details page. The loading sub-state is due to the network request to fetch the entire post details originated from the <em>model</em> hook. If we suppress the model hook, then loading screen will not be pulled in. Great! but, how to do that?</p><p>While transitioning to the details view, if we pass along the model data, the model hook present in the details page will not be invoked, instead, the data sent from the list page will be used as a model.</p><pre>// routes/posts.js - Before </pre><pre>this.transitionTo(&#39;post.details&#39;, post.id);</pre><pre>// routes/posts.js - After </pre><pre>this.transitionTo(&#39;post.details&#39;, post);</pre><p>Here, post will be the limited data from the list page. Here, the point to be noticed is that the <em>data needs to be normalized</em> as same as that of the model we maintain in details page to avoid breakages.</p><p>For instance, if you structure the post data in the details page to be inside an object with key details, then you have to normalize it correctly.</p><pre>// routes/posts.js </pre><pre>let postDetails = {<br>   details: post // from the list page<br>}<br>this.transitionTo(&#39;post.details&#39;, postDetails);</pre><p>If you have done this far, then you are awesome! Now your details page should be loaded instantly without any loading sub-state. Hi-Fi 🙌</p><p>But you can also notice that our page will be half-baked. No worries! We gonna fix that. As mentioned earlier, we have to fetch the <em>remaining</em> data while the user digests the available data. For this, we can trigger a data fetch inside the setupController hook to pull out the remaining data.</p><pre>// routes/posts/list.js</pre><pre>setupController(controller, model) {<br>  this._super(...arguments);<br>  let postId = model.details.id; // passed data from the list<br>  controller.get(&#39;fetchPostMeta&#39;).perform({ postId });<br>  controller.get(&#39;fetchComment&#39;).perform({ postId });<br>}</pre><p>In the above snippet, I’ve used ember-concurrency tasks to fetch the remaining post details and comments for that post. Until the task finish and data loads in the UI, we could use a loading symbol on appropriate positions. Again we have to properly normalize the lazily loaded data. One extra hack to again improve the perceived performance here is to use skeleton loader in place wherever possible. There is another great article about <a href="https://emberway.io/skeleton-screen-loading-in-ember-js-2f7ac2384d63">skeleton loading in Ember.js</a> by <a href="https://medium.com/u/a4c91dcedec4">Lauren Elizabeth Tan</a>. Check for detailed implementation 😃</p><p>After implementing the <strong>NIL pattern</strong>, our sample app would be something like as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*Tq7AlKrG3F0i1UQQ.gif" /><figcaption>App with NIL pattern implemented</figcaption></figure><p>You can see that the author of the blog as well as the comments has been lazily loaded. This is probably a lot better than the previous version where the users have to wait for a while to get some content on the screen.</p><p>Hope this helps you save few moments of your users 🙂 That’s a big win right! 😉 Completed twiddle can be found <a href="https://ember-twiddle.com/ab964da9e161c5a7996b1677f3eb09c5?openFiles=templates.posts.details.hbs%2C&amp;route=%2F1">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fa13e96274d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Electron - autoUpdater 101]]></title>
            <link>https://gokatz.medium.com/electron-autoupdater-101-f5a268766e75?source=rss-7a1aeba9bdb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5a268766e75</guid>
            <category><![CDATA[electronjs]]></category>
            <category><![CDATA[desktop-app]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Gokul Kathirvel]]></dc:creator>
            <pubDate>Fri, 26 May 2017 08:50:46 GMT</pubDate>
            <atom:updated>2021-01-02T05:24:03.409Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HITS1SUtQwUmEsn3UycxQ.png" /><figcaption>Electron</figcaption></figure><p>👉<em> Originally published on </em><a href="https://gokatz.me/blog/electron-autoupdater-101/"><em>gokatz.me</em></a><em>. Follow here for regular updates and more on Electron — </em><a href="https://gokatz.me/blog/electron-autoupdater-101/">https://gokatz.me/blog/electron-autoupdater-101/</a></p><p>Yes, It’s 2017… You can build native desktop apps with the very superior language of the web, <strong><em>Javascript</em></strong>. Thanks to the entire team of <a href="https://github.com/electron/electron/graphs/contributors">contributors</a> of <a href="https://electron.atom.io/">Electron</a>, the job got a lot more easier. You can now develop a web app without any special attention to be paid to electron and wrap the same with a container that helps to run the app in various native platforms.</p><p>I don’t need to talk much about the web app development as you might be well experienced than me 😉 Post development process needs attention here. That being said, major attention must be given to building &amp; packaging process and again thanks to the team for the <a href="https://github.com/electron-userland/electron-packager">electron-packager</a> which helps in packaging out-of-the-box. Now let us talk about <strong>distribution…</strong></p><p>Now comes the core of the story. Yeah, you are right, distribution may happen seriously in hell a lot of ways.</p><p><em>You may</em></p><ul><li>Pack up the app and mail it to your peer dev to test.</li><li>Want to distribute it internally to all your team.</li><li>Need to distribute it to your customers via Mac App Store or Windows store or something similar</li></ul><p>In this part of the my electron-series ( <em>yeah, planning for a series</em> ), I’m going to explain about the second one in the list as the first one will be straight forward. Distributing a native app with your team is as easy as sending the packed app to your team mail. It’s that’s simple! Hope this helps you. Meet you in the next series…</p><p><strong>Just Kidding… </strong>😉😛</p><p>Actually I’m not kidding entirely. Distributing a native app built with electron, without any honey mix, is just a mail away. But, adding honey drops such as <strong>autoUpdater </strong>will be somewhat tricky especially for non-native guys like me.</p><blockquote><em>autoUpdater</em> is nothing but a built-in tool in electron to enable the app to be auto-updated automatically when a new version of the app gets released.</blockquote><p>This is something significant in my case. I was building a QA app for internal usage for my team. The issue with the native app is that, the updates should be patched up and released with a considerable amount of changes and users have to re-install it every time. In my case, I can’t expect that my fellow devs to check for updates to download and re-install the app every time I release an update. So, I decided to go with the auto update feature of electron. I will be explaining the whole process with respect to Mac OS. I Will be covering about Windows and<em> may be Linux </em>in my future posts.</p><p>The three major glitches I faced were…</p><ul><li>Code-signing the packaged app (mandatory, in case of OS X).</li><li>Setting up an electron update server.</li><li>Configuring the app for aut0-update.</li></ul><p>Code-signing is one of the mandatory steps for enabling autoUpdater for Mac app. <em>Code-signing</em> the mac app is actually a very easy process with 3 terminal commands if you do it manually. But, lack of documentation and scattered notes made it a hell. With respect to <em>electron, </em>you don’t even dive into terminal for this. Its handled for you internally!</p><p>Let’s get started with the code-signing process and make your hands dirty with few lines of code 😊 The first thing you need to know is that, you need a <strong><em>Developer ID Application certificate </em></strong>to distribute a mac app outside Mac AppStore. Ordinary <em>Mac Developer certificate</em> for development cannot be used to code-sign the mac app. Certificate will be something similar to <strong><em>Developer ID application &lt;company name&gt; (&lt;identity&gt;)</em></strong>, as in the snap (highlighted one).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uM-2aUk8CJfjrFsHg8hUSw.png" /></figure><p>This certificate can be generated by the member with <strong><em>Team-Agent</em></strong><em> </em>role. If your role is not Team-Agent, then find someone with this role and ask them to generate this certificate from apple developer console. Mostly, your mobile team-lead will have one.</p><p>Once you get your <em>Developer ID Application certificate</em>, just install (double-click open) it in your <em>Keychain Access</em>.</p><p>You are now half way 🔥. Now lets dive into the actual signing setup. This is super simple. Just add the appropriate certificate in your <em>forge-config</em> file (if you have one) or in your <em>package.json </em>under<em> </em><strong><em>electronPackagerConfig</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60491b29163210ecf7597d89ff795d21/href">https://medium.com/media/60491b29163210ecf7597d89ff795d21/href</a></iframe><p>HoHooo…! You signed the app that needs to be distributed. If anything goes wrong. Try to sign your .app file manually using the certificate by following the instructions mentioned <a href="https://pracucci.com/atom-electron-signing-mac-app.html">here</a>. If you use any invalid certificate, then in the last step, the app will get a <strong>rejected </strong>message i.e, the terminal will spit out &lt;appName&gt;.app: rejected. So, be sure to have a <strong><em>valid certificate</em></strong> 👾.</p><p>Next up, the setup process of the update server.</p><p>Backend support for auto-update can be achieved via three major packages as mentioned in the <a href="https://electron.atom.io/docs/api/auto-updater/">official docs</a> (strongly recommend you to skim through it). I assume that in most of the scenarios, github cannot be used for backing up the release as our apps would not be opensource. So, I prefer <strong><em>electron-release-server</em></strong> to serve the updates which involves self hosting using postgres DB. Again, the <a href="https://github.com/ArekSredzki/electron-release-server">official docs</a> itself is a self explanatory one for someone who already has some knowledge on backend techs and databases. But as a front end guy, it took me a while to get this setup done as the setup instructions were scattered on 3 to 4 github documentation pages. Luckily, I got help from one of my peer dev who has knowledge on postgres. I’ll compile those steps here.</p><p><strong>Step 1:</strong></p><p>Install postgres using a brew command - brew install postgres . This command needs brew preinstalled in your machine. That’s only a <a href="https://brew.sh/">command away</a>. After a successful installation, running postgres --version should output a version of postgres (not to worry, unless the message is something like postgres: command not found 😉 )</p><p>After installing the postgres DB, make sure you start the server with the command.</p><pre>pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start</pre><p>The path `usr/local/var/postgres` is hardcoded, as generally <em>postgres</em> will be installed in this location. After starting the server, create a DB and port into in it using</p><pre>createdb &lt;db name - of your choice&gt;<br>psql &lt;db name&gt;</pre><p>After starting the server, we have to create a postgres role.</p><pre>CREATE ROLE electron_release_server_user ENCRYPTED PASSWORD &#39;&lt;PASSWORD&gt;&#39; LOGIN;</pre><p>replace &lt;PASSWORD&gt; with your original password. You can replace <em>electron_release_server_user </em>with the name of your choice (<em>you may need to follow this name in the following configurations too</em>) . I would advise you to leave it undisturbed and go with the default one.</p><p>Now, we have to create databases for the role and session.</p><pre>CREATE DATABASE electron_release_server OWNER &quot;electron_release_server_user&quot;;<br>CREATE DATABASE electron_release_server_sessions OWNER &quot;electron_release_server_user&quot;;</pre><p>That’s it! You have created a dedicated DB and role for our release process.</p><p><strong>Step 2:</strong></p><p>Now it’s time to setup deployment. The default adapter is <em>sail deployment adapter.</em> Clone the <em>sails-pg-session</em> adapter and copy the sql dump into your postgres DB using the following commands.</p><pre>git clone <a href="https://github.com/ravitej91/sails-pg-session.git">https://github.com/ravitej91/sails-pg-session.git</a><br>cd sails-pg-session</pre><pre>psql electron_release_server_sessions &lt; ./sql/sails-pg-session-support.sql</pre><p>Kindly, ensure that you name the session as <em>electron_release_server_sessions.</em> If you have any custom names, kindly replace it with the same.</p><p><strong>Step 3:</strong></p><p>Next, follow the below commands to install <em>electron-release-server</em> and its dependencies.</p><pre>git clone <a href="https://github.com/ArekSredzki/electron-release-server.git">https://github.com/ArekSredzki/electron-release-server.git</a><br>cd electron-release-server<br>npm install</pre><p>Now, we need to create a <em>config.js</em> file. <em>electron-release-server</em> has a built-in config template. Let’s copy that for simplicity using cp config/local.template config/local.js</p><p>Open the file <em>config/local.js</em> and replace the connection and session object with the following snippet. As long as you follow the default naming convention, your session and connection object will be like</p><pre>connections: {<br>        postgresql: {<br>        adapter: &#39;sails-postgresql&#39;,<br>        host: &#39;localhost&#39;,<br>        user: &#39;electron_release_server_user&#39;,<br>        password: &#39;&lt;PASSWORD&gt;&#39;, // replace with your password <br>        database: &#39;electron_release_server&#39;<br>        }<br>    },</pre><pre>    session: {<br>        secret: &#39;&lt;your secret&gt;&#39;, // Generate using: https://www.grc.com/passwords.htm<br>        database: &#39;electron_release_server&#39;,<br>        host: &#39;localhost&#39;,<br>        user: &#39;electron_release_server_user&#39;,<br>        password: &#39;&lt;PASSWORD&gt;&#39;, // replace with your password<br>        port: 5432<br>    }</pre><p>And then, add the appUrl (where the <em>electron-release-server</em> is running, as of now, its <a href="http://localhost/"><strong><em>http://localhost</em></strong></a>) and authentication variable (for admin access) in the <em>local.js</em> file. So that, your config/local.js file should look something like <a href="https://gist.github.com/gokatz/0451c93c371997adc865556eb2af79af#file-local-js-L35-L81">this</a>. As a last note, make sure you are in latest Node version (LTS). You can download the LTS release <a href="https://nodejs.org/en/">here</a></p><p><strong>Hi-fi… </strong>🖐️<strong> </strong>You are almost done. Let’s drive the server with the command npm run start from the root of the project. If it fails, use with <em>sudo — </em>sudo npm run start</p><p>Keep calm and wait for the server to deploy successfully and check <a href="http://localhost/">http://localhost</a> to see your beautiful release console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFS6gKMyIT7fMa97G73sxg.png" /><figcaption>Electron release server — Home screen</figcaption></figure><p>Configuring your electron project for auto-update is fairly simple and you can follow the <a href="https://electron.atom.io/docs/api/auto-updater/">doc</a>. All the events have been explained well in the doc. As a debugger hand, you can use <a href="https://github.com/winstonjs/winston">winston logger</a> to debug the event hooks. Following is the <em>main.js</em> snippet with the debug code. Actually, thanks to <a href="https://medium.com/u/8735e80bcaa5">lazlojuly</a> for introducing winston to me 😉</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4abdc0c467b83b3e30bdb9e1deb3de10/href">https://medium.com/media/4abdc0c467b83b3e30bdb9e1deb3de10/href</a></iframe><p>Hey dude… Do you know something… You are done 💪 Build your app with a <strong>valid certificate </strong>(saying it many times as it needs to be)<strong> </strong>and upload the zipped asset to the <em>electron-release-server! electron-release-server</em> has a small video on uploading the assets into server and you can find it <a href="https://www.youtube.com/watch?v=lvT7rfB01iA">here</a>. Before uploading it into the server, run it once in you machine to check for the certificate validations. For accessing the admin panel, use the username and password you configured in <em>electron-release-server’s local.js </em>file<em>.</em></p><h3>Wrap UP ⬆️</h3><p>autoUpdater is an awesome feature in electron and worth exploring it. I have narrated the entire flow with respect to my own use case. If you have any specific stuffs that need to be clarified, you can comment out here and reach me out via <a href="https://twitter.com/_gokatz">twitter</a>. I’ll try to help you out. You should join electron’s <a href="https://atom-slack.herokuapp.com/">Slack channel</a> as well as <em>electron-release-server</em> <a href="https://gitter.im/ArekSredzki/electron-release-server">Gitter channel</a> to get more info. Dudes out there were awesome 🏅Thanks for your time for this post.</p><p>PS: This is my first post on <em>Medium</em> 😇 So, Comment-box is waiting for your feedbacks and suggestions 😋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5a268766e75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>