In this tutorial, we’re going to build a Google Chrome extension to save web content to . Think of it as your personal web clipper. Cosmic JS Buckets TL;DR Download the code from the GitHub repo Pre-requisites You just need to have Chrome installed for testing it out and nothing else. Installing the demo Get the source code into your machine by either downloading or cloning the repo, which is located here . In Chrome, visit chrome://extensions Enable Developer mode by ticking the checkbox in the upper-right corner. Click on the “Load unpacked extension…” button. Select the directory containing your extension. unpacked Refresh loaded pages. You’ll now see the extension icon to the right of the Omnibox. Click on it and login with your Cosmic JS credentials. You can now start saving content to your buckets. Understanding the Source Code The defining file in a Chrome extension is the file. Most of the fields in the Manifest are self explanatory. Let’s go through the major fields, and see what each file do. manifest.json is "2". it is very important not change it because it is a sign to chrome to how to compile the extension. manifest_version includes the permissions which extension needs- permission allows you to store data at "Chrome local storage" which is important to save data across websites and different pages. - permission gives access to retrieve and send data from and to the API anywhere in the extension. permissions storage https://api.cosmicjs.com/v1 contains "default_icon" and "default_popup" which related with top bar icon and HTML file browser_action this is an important part which it contains scripts which injected into websites- tells the browser tp inject the scripts to any protocol [http, https,...] and any domain. content_scripts matches: [*://*/*] - field contains CSS style sheets to be injected css - field contains JavaScript files to be injected js - is true which tells to inject script to all frames like "iframe" tag . it is important to make the extension work everywhere all_frames include background scripts which manage send data to Cosmic JS and checks authorization background The JavaScript files in the js folder is where the whole functionality is resided. file contains all the functions of the extension. file uses jquery and to manage the extension function is matched websites. file periodically calls the authorization function and also sends data to the Cosmic bucket. myscript.js contentscript.js myscript.js background.js Conclusion The advantage of API-first content management systems is that there is no limit as to where you can integrate your app into. Your Cosmic JS Bucket can thus power your web app, native app, browser extensions or basically anything than can consume an API. If you have any questions, please reach out to us on or join our community. Twitter Slack . This article originally appeared on Cosmic JS
Share Your Thoughts