<?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 Esteban on Medium]]></title>
        <description><![CDATA[Stories by Esteban on Medium]]></description>
        <link>https://medium.com/@esbanarango?source=rss-a397c6a20aa3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ucRmSzJ2sKAETNU0.jpeg</url>
            <title>Stories by Esteban on Medium</title>
            <link>https://medium.com/@esbanarango?source=rss-a397c6a20aa3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:45:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@esbanarango/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[A framework for ambitious Chrome Extensions]]></title>
            <link>https://medium.com/@esbanarango/a-framework-for-ambitious-chrome-extensions-b08d1f4b944d?source=rss-a397c6a20aa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b08d1f4b944d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[emberjs]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Esteban]]></dc:creator>
            <pubDate>Mon, 06 Aug 2018 16:54:23 GMT</pubDate>
            <atom:updated>2018-09-26T17:22:56.952Z</atom:updated>
            <content:encoded><![CDATA[<p>At Envoy, we love Ember.js. We enjoy coming to work every day and not worrying about set-ups, naming things, or doing repetitive tasks. We love <em>convention over configuration</em> (yes, we also use Ruby on Rails). The Ember ecosystem is great, full of amazing <a href="https://www.emberaddons.com/">add-ons</a>, a wonderful community, a strong testing culture, and one of the greatest <a href="https://ember-cli.com/">command line interfaces</a>. That’s why every time we need to build something new on the front-end we ask ourselves, can we use Ember here? Is it the right tool for this problem? Sometimes the answer to that question is no (we also use React); but usually it is <strong>yes</strong>. Besides, using Ember makes it so easy to transfer knowledge between different projects and we have now nine engineers working almost full-time with Ember.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Im2vmwrsdnGiOgMNrCqUwA.gif" /><figcaption>Source: <a href="https://dribbble.com/shots/1996259-Swiss-army-knife">https://dribbble.com/shots/1996259-Swiss-army-knife</a></figcaption></figure><p>This time we needed to build a Chrome extension, so we asked that question again; the answer ended up being… “maybe”. There are a ton of great <em>starter</em> and <em>boilerplate</em> projects on Github for building extensions, but we found out that with <a href="https://ember-cli.com/">ember-cli</a> and the right mix of add-ons, it would be more than enough to have a solid environment to work with.</p><p>So here I’m going to share the path we took to build a Chrome extension using Ember.js and the things we would have wanted to know a couple weeks ago.</p><h3>Final app</h3><p>Some context of what wanted to build: we needed a single Chrome extension with multiple components sharing a <strong>single</strong> Ember code-base. These extension components were:</p><blockquote><a href="https://developer.chrome.com/extensions/browserAction"><strong>Browser/Page Action popup</strong></a><strong>:</strong> A small window that’s opened with a click on the corresponding UI element.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*c5w25F71yLQeAGCnYn-GGw.png" /></figure><blockquote><a href="https://developer.chrome.com/extensions/content_scripts"><strong>Content Scripts</strong></a><strong>:</strong> A script that runs alongside pages; for compatibility reasons, it <a href="https://developer.chrome.com/extensions/content_scripts#execution-environment">runs in an isolated world</a>, but it shares the DOM with the page, and as such can modify it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CEpN6DCBM2mMtSyOp940ew.png" /></figure><p>One of the coolest parts of the <em>Content Scripts</em> isolated world is that you can inject any library or code into a website and not worry about any conflicts with existing JS running there. You can have different versions of frameworks or trigger different events, plus you can share the DOM 🔝.</p><h3>Initial setup and configuration</h3><p><a href="https://github.com/rmachielse/ember-cli-deploy-chrome-app">ember-cli-deploy-chrome-app</a> is the initial boilerplate for an Ember Chrome extension and the easiest way to integrate CI and all the deployment processes to the Chrome Web Store.</p><blockquote>It generates a chrome folder and a key.pem file in the root of your project. In chrome you&#39;ll find background.js and a default manifest.json that you can change according to your needs.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*jM-2u7Q1DUnIyT7S06qlDg.gif" /></figure><p>This chrome folder will have mostly configuration files and references to our Ember app. It also includes some handy symlinks pointing to the dist folder to access those files.</p><p>⚠️ Because we will need a <em>Content Script </em>extension component<em> </em>(which injects scripts into a page), symlinks do not work in this scenario. So every time the Ember app is built, we need to copy files from dist into chrome.</p><p>Obviously there is an add-on for that: <a href="https://github.com/tgsoverly/ember-cli-post-build-copy">ember-cli-post-build-copy</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dbb09352808c593d9724d746494e237/href">https://medium.com/media/9dbb09352808c593d9724d746494e237/href</a></iframe><p>You may have noticed we’re only copying two files here, app.js and app.css. But a normal Ember app has also a vendor.js and avendor.css. We used <a href="https://github.com/tgsoverly/ember-cli-post-build-copy">ember-cli-concat</a> to have a single file of JS and CSS so we can manage them more easily.</p><p>We won’t have an index.html here either. Therefore, we have to turn off <a href="https://ember-cli.com/user-guide/#application-configuration">storeConfigInMeta</a>, so that all the config data is included in the app.js.</p><p>Finally our ember-cli-build.js will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f67396ee99befc781f5528d0fa724bc/href">https://medium.com/media/6f67396ee99befc781f5528d0fa724bc/href</a></iframe><h4>Booting up the Ember app</h4><p>In order to share a single code-base with these extension components, we needed to manually control the booting of the application. Specifically for the <em>Content Script</em> part, where we want to wait until the user performs an action to render the app.</p><p>We can easily configure it by setting autoboot: false and calling</p><pre>require(&#39;chrome-extension/app&#39;)[&#39;default&#39;].create({ rootElement: &#39;#selector&#39; });</pre><p>later when needed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5792808378a3eb7e7d68beca1c9d2d72/href">https://medium.com/media/5792808378a3eb7e7d68beca1c9d2d72/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b419d6e61baf5391f9c97de325d05c13/href">https://medium.com/media/b419d6e61baf5391f9c97de325d05c13/href</a></iframe><p>⚠️ We need to make sure we’re loading the JS files in the right order, so we can have access to require(&#39;chrome-extension/app&#39;)[&#39;default&#39;]</p><pre>// chrome/manifest.json</pre><pre>&quot;content_scripts&quot;: [<br>  {<br>    &quot;matches&quot;: [&quot;<a href="https://calendar.google.com/calendar/*">https://website/where-i-will-run-this-code/*</a>&quot;],<br><strong>    &quot;css&quot;: [&quot;assets/app.css&quot;],<br>    &quot;js&quot;: [<br>      &quot;assets/app.js&quot;,<br>      &quot;content-script.js&quot;<br>    ],</strong><br>    &quot;run_at&quot;: &quot;document_idle&quot;<br>  }<br>],</pre><blockquote>If you want to learn more deeply about how an Ember app boots, I highly recommend:</blockquote><p><a href="https://hackernoon.com/how-does-ember-boot-5e1f9e7a1117">How does Ember Boot?</a></p><p>Because we set autoboot: false, we also need to manually boot up the Ember app on the <em>pop up</em> side.</p><pre>// chrome/manifest.json</pre><pre>&quot;browser_action&quot;: {<br>  &quot;default_icon&quot;: {<br>    &quot;16&quot;: &quot;images/logo-icon-16.png&quot;<br>  },<br>  &quot;default_title&quot;: &quot;Ember&quot;,<br>  <strong>&quot;default_popup&quot;: &quot;popup.html&quot;</strong><br>},</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d585690d729cff639c33ff2afe0e4aa9/href">https://medium.com/media/d585690d729cff639c33ff2afe0e4aa9/href</a></iframe><p>Lastly, we need to know where we are booting the Ember app from, so we can know which logic to use or which components to render. For this, we add a &lt;meta&gt; tag to the popup.html file, so can get its content from the <em>application controller</em>.</p><pre>// popup.html</pre><pre>&lt;meta scope=”ember-app-from” content=”popup”&gt;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e649fc6f97213d653e2eaa19b897b117/href">https://medium.com/media/e649fc6f97213d653e2eaa19b897b117/href</a></iframe><h4>Working with the Chrome API inside an Ember app</h4><p>Access to the <a href="https://developer.chrome.com/extensions/api_index">Chrome extension API</a> is available inside the Ember app from any file at any time. You can either use /* global chrome */ on files where you’re using it or just add it to your .eslintrc.js file so ESLint doesn’t yell at you.</p><pre>// .eslintrc.js</pre><pre>module.exports = {<br>  globals: {<br>    $: true,<br>    <strong>chrome: true,</strong><br>    window: true<br>  }<br>}</pre><p>One of the APIs we needed was <a href="https://developer.chrome.com/extensions/storage">chrome.storage</a>. We use it to save and share the “session” between the <em>popup </em>component<em> </em>and the <em>content script. </em>It provides the same storage capabilities as the normal localStorage API that you would have access to on any web app.</p><blockquote><em>When using </em>storage, <em>the </em>extension’s content scripts<em> can directly access user data without the need for a background page.</em></blockquote><p>To use almost all of these APIs you need request permission when the user is installing the extension. Just specify these permissions in your manifest file.</p><pre>// chrome/manifest.json</pre><pre>&quot;permissions&quot;: [&quot;tabs&quot;, &quot;activeTab&quot;, &quot;storage&quot;, &quot;management&quot;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*yysB4Dh_FJK2Cnw6.jpg" /></figure><p>One of the must-install add-ons in any Ember app is <a href="http://ember-concurrency.com/docs/introduction/">Ember-Concurrency</a> (EC), as it makes it so easy to write concise, robust, and beautiful asynchronous code. We certainly wanted to use it here. But <a href="https://developer.chrome.com/extensions/api_index">Chrome extension API</a> uses a callback design structure API. In order to convert all these “callback hell” functions into something we can plug-in inside any EC task we needed: <a href="https://github.com/tfoxy/chrome-promise">chrome-promise</a>. With it, we canyield any call to the Chrome extension API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64d0d661d13c19f07f46097bd8cbdb27/href">https://medium.com/media/64d0d661d13c19f07f46097bd8cbdb27/href</a></iframe><h4>Installing the Chrome extension locally</h4><ul><li>Open the Extension Management page by navigating to <a href="/service/chrome://extensions">chrome://extensions</a>.</li><li>Enable Developer Mode by clicking the toggle switch next to Developer mode.</li><li>Click the LOAD UNPACKED button and select the extension directory (/chrome).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*vdSo0q6xD1lt15eKIvgCow.gif" /></figure><h4>Live reloading</h4><p>⚠️ Because we’re in an encapsulated environment, the WebSocket connection created by <em>ember-cli-inject-live-reload </em>won’t work here. Instead we need to watch for file changes under thechrome folder. For this we can use <a href="https://github.com/xpl/crx-hotreload">https://github.com/xpl/crx-hotreload</a>. When a change is detected, it reloads the extension and refreshes the active tab (to re-trigger the updated scripts).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwZE0DUWPv1-PySfqPT9BA.gif" /></figure><h4>🚨 Known limitations</h4><ul><li>Chrome apps currently seem unable to handle HTML5 pushState. Make sure locationType is set to hashin your config/environment.js file.</li><li>Depending on your configuration, you might need to disable fingerprinting. If you have symlinked chrome/window.htmlto dist/index.html, the asset urls in app/index.html will be compiled like normal. However, if you have a different window.html, it will not be compiled and thus will unable to handle fingerprinted assets. In that case you have to disable it in ember-cli-build.js by setting fingerprint to { enabled: false }.</li></ul><h4>Conclusions</h4><p>We felt really confident working and publishing this extension, it has a good test coverage, it shares the same patterns we use on our main Ember app and we know that any engineer can jump on it and add new features or fix bugs. We’re basically speaking the same language as if we were working on a normal web app. At the end an Ember app is simply a .js file plus a .css, so with the correct configuration you can basically port it anywhere you want.</p><p>Finally, by sharing this, we hope to encourage more people to have Ember.js as an option when creating Chrome apps. The Chrome API and the Ember.js ecosystem is a powerful mix for building <em>ambitious</em> <em>Chrome</em> <em>extensions</em>.</p><h3>(((Ian Irving)) 🍁 on Twitter</h3><p>@esbanarango always forget that #EmberInspector is a (brilliant) Ember app and Chrome extension that I use every day. #EmberJs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b08d1f4b944d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>