Table of Contents
Introduction
What is a Chrome Extension?
A Chrome extension is a small software program that customizes the browsing experience on the Google Chrome browser. It enables users to tailor Chrome’s functionality and behavior to individual needs or preferences. Extensions are built using web technologies such as HTML, JavaScript, and CSS and can range from simple utilities to complex applications. They can enhance productivity, provide quick access to information, or even alter the way you interact with web content.
Extensions integrate seamlessly into Chrome, offering a high degree of convenience and efficiency. They’re accessible through the browser’s toolbar and can interact with the web pages you visit, or operate as standalone tools.
The Note-Taking Extension: An Overview
In this tutorial, we will embark on an exciting journey to create a Note-Taking Chrome Extension. This extension is designed as a quick and easy tool for users to jot down notes without leaving their browser. Whether it’s capturing thoughts, creating to-do lists, or saving snippets of text from web pages, this extension will serve as a handy companion for your daily browsing activities.
Key Functionalities:
- Quick Note-Taking: Users can easily write and save notes directly from the browser.
- Note Management: Each note consists of a date, a bold title, and the note content itself. Users can effortlessly add, edit, and delete notes.
- Local Data Storage: Notes are stored locally, ensuring quick access and privacy.
This extension aims to enhance productivity and information management for everyday Chrome users. Whether you’re a student, professional, or just someone with a lot to remember, this note-taking tool is designed to keep your important notes just a click away.
In the following sections, we’ll dive into the technical details, guiding you through each step of creating this extension, from setting up the project to writing the code and testing the final product.
Prerequisites:
- Basic understanding of HTML, JavaScript, and CSS.
- Google Chrome browser installed.
- Text editor (like Sublime Text, Notepad++ Visual Studio Code, Atom, etc.).
Tutorial
1. Setting Up the Project
Create Project Folder
To start, create a new folder on your computer. This will be the main directory for your Chrome extension. Organize your folder by creating separate files for HTML, CSS, and JavaScript, ensuring a clean and manageable structure. This organization is crucial for maintaining your code efficiently as the project grows.
Manifest File
Central to every Chrome extension is the manifest.json file. This JSON-formatted file provides Chrome with information about your extension, such as its name, version, and which files to run. Create a manifest.json file in your project folder and include essential details like your extension’s name, description, version, and the permissions it requires. This file acts as the backbone of your extension, instructing Chrome on how to handle it (find below the demo code manifest.json file).
2. Building the User Interface with HTML and CSS:
Date Field
Create an input field for the date. This allows users to record the current date for each note, adding context and organization to their notes.
Note Title
Include a text input for the note’s title. Style this element to display the title in bold, making it visually distinct and easy to identify.
Note Body
Add a textarea element for writing the note’s content. This provides ample space for users to jot down their thoughts or information.
CSS Styling
Focus on creating a user-friendly and visually appealing interface. Use CSS to:
- Ensure legibility with clear fonts and contrasting colors.
- Provide a comfortable user experience with appropriate spacing and sizing of elements.
- Enhance usability with intuitive layouts and responsive design.
Applying these styling tips will make your note-taking extension both functional and attractive, enhancing the overall user experience.
3. Adding Functionality with JavaScript
Save Note Function
- Capturing Data: Use JavaScript to gather data from the date, title, and note body fields when a user clicks the ‘Save’ button.
- Storing Notes: Implement code to store these notes in the browser’s local storage. This allows the notes to persist even after the browser is closed and reopened.
Delete Note Function
- Individual Deletion: Provide functionality that enables users to delete specific notes. This involves identifying the note to be deleted and removing it from local storage.
Edit and Update Notes
- Editing Capability: Allow users to edit existing notes. This requires loading the selected note’s data back into the input fields for modification.
- Updating Notes: After editing, the note should be saved again, updating the existing entry in local storage rather than creating a new one.
Displaying Saved Notes
- Dynamic Display: Implement a system to dynamically display all saved notes on the extension page. This involves reading the notes from local storage and rendering them in the UI every time the extension is opened or a note is added, edited, or deleted.
Summary Table:
| Section | Key Points | Tools/Technologies Used |
|---|---|---|
| Setting Up the Project | Project structure, manifest file | Text Editor, JSON |
| Building the UI | HTML fields, CSS styling | HTML, CSS |
| Adding Functionality | JavaScript for saving, editing, deleting notes | JavaScript, Chrome APIs |
| Testing the Extension | Loading and debugging the extension | Chrome Developer Tools |
| Conclusion & Resources | Recap, further learning resources | – |
And now… Your code
Below is an outline of the code for each part of the extension:
1. Manifest File (manifest.json)
This file is essential for any Chrome extension. It defines basic settings like your extension’s name, version, and which scripts to run.
{
 "manifest_version": 3,
 "name": "Quick Note Taker",
 "description": "A simple note-taking extension.",
 "version": "1.0",
 "action": {
  "default_popup": "popup.html",
  "default_icon": "icon.png"
 },
 "permissions": ["storage"],
 "background": {
  "service_worker": "background.js"
 }
}
Note: You’ll need to create an icon.png file for the extension’s icon.
2. Popup HTML (popup.html)
This is the HTML for the popup that appears when you click the extension icon.
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="popup.css">
</head>
<body>
  <div id="noteContainer">
    <input type="date" id="noteDate">
    <input type="text" id="noteTitle" placeholder="Note Title" style="font-weight:bold;">
    <textarea id="noteBody" placeholder="Your note..."></textarea>
    <button id="saveButton">Save Note</button>
  </div>
  <div id="notesList"></div>
  <script src="popup.js"></script>
</body>
</html>
3. Popup CSS (popup.css)
This CSS file will style your HTML popup.
body {
  width: 300px;
  padding: 10px;
}
#noteTitle, #noteDate, #noteBody {
  width: 100%;
  margin-bottom: 10px;
}
#noteBody {
  height: 100px;
  resize: none;
}
#notesList {
  margin-top: 20px;
}
4. Popup JavaScript (popup.js)
This JavaScript file will handle the logic for saving, displaying, and deleting notes.
document.getElementById('saveButton').addEventListener('click', saveOrUpdateNote);
let editingNoteIndex = null;
function saveOrUpdateNote() {
  let noteDate = document.getElementById('noteDate').value;
  let noteTitle = document.getElementById('noteTitle').value;
  let noteBody = document.getElementById('noteBody').value;
  let note = { date: noteDate, title: noteTitle, body: noteBody };
  let notes = localStorage.getItem('notes') ? JSON.parse(localStorage.getItem('notes')) : [];
  if (editingNoteIndex !== null) {
    notes[editingNoteIndex] = note;
    editingNoteIndex = null;
  } else {
    notes.push(note);
  }
  localStorage.setItem('notes', JSON.stringify(notes));
  displayNotes();
  clearInputs();
}
function displayNotes() {
  let notes = localStorage.getItem('notes') ? JSON.parse(localStorage.getItem('notes')) : [];
  let notesList = document.getElementById('notesList');
  notesList.innerHTML = '';
  notes.forEach((note, index) => {
    let noteDiv = document.createElement('div');
    noteDiv.innerHTML = `
      <p><strong>${note.title}</strong> (${note.date})</p>
      <p>${note.body}</p>
      <button id="editButton-${index}">Edit</button>
      <button id="deleteButton-${index}">Delete</button>
      <hr>`;
    notesList.appendChild(noteDiv);
    document.getElementById(`editButton-${index}`).addEventListener('click', function() {
      editNote(index);
    });
    document.getElementById(`deleteButton-${index}`).addEventListener('click', function() {
      deleteNote(index);
    });
  });
}
function deleteNote(index) {
  let notes = JSON.parse(localStorage.getItem('notes'));
  notes.splice(index, 1);
  localStorage.setItem('notes', JSON.stringify(notes));
  displayNotes();
}
function editNote(index) {
  let notes = JSON.parse(localStorage.getItem('notes'));
  document.getElementById('noteDate').value = notes[index].date;
  document.getElementById('noteTitle').value = notes[index].title;
  document.getElementById('noteBody').value = notes[index].body;
  editingNoteIndex = index;
}
function clearInputs() {
  document.getElementById('noteDate').value = '';
  document.getElementById('noteTitle').value = '';
  document.getElementById('noteBody').value = '';
}
// Initial display of notes
displayNotes();
5. Additional File: Background JavaScript (background.js)
You should also create a simple background.js file, even if it’s empty, as Manifest V3 requires the declaration of a background service worker:
// background.js
// This can remain empty if you're not using background scripts
Note on Local Storage:
In Manifest V3, the use of chrome.storage API is recommended over localStorage for extension data. chrome.storage is asynchronous and more suitable for extension data that needs to be accessible across different parts of the extension. However, for simplicity, you can still use localStorage in your popup scripts.
Additional Notes:
1. Deleting Notes
We need to ensure that the delete button correctly identifies which note to delete. This can be achieved by passing the correct note index to the deleteNote function.
2. Editing Notes
To add the ability to edit notes, we’ll introduce an ‘Edit’ button for each note. When clicked, it should load the note back into the input fields for editing. We’ll also modify the save functionality to update an existing note if it’s being edited
How it Works:
- Deleting Notes: When the ‘Delete’ button is clicked,
deleteNoteis called with the index of the note. This function then removes the note from the array and updates local storage. - Editing Notes: When the ‘Edit’ button is clicked,
editNoteloads the note data into the input fields and stores the note’s index ineditingNoteIndex. IfeditingNoteIndexis not null,saveOrUpdateNoteupdates the existing note instead of creating a new one. - Clearing Inputs: After saving a note, the input fields are cleared, ready for a new note.
Remember to test these new functionalities thoroughly to ensure they work as expected. You can also enhance the UI/UX to make it clear to the user when they are editing an existing note versus adding a new one.
Instructions for Testing the Extension:
- Create a folder and place these four files inside it.
- Open Google Chrome and go to
chrome://extensions/. - Enable “Developer mode” (usually a toggle at the top-right).
- Click “Load unpacked” and select your folder.
- Your extension should now appear in your toolbar. Click it to open the popup.
This code provides a basic note-taking functionality where notes are stored in the browser’s local storage. You can expand and customize it further based on your needs and the preferences of your blog audience.
Conclusion
In this tutorial, you’ve learned the essentials of creating a functional and user-friendly note-taking Chrome extension. From setting up your project structure and crafting the HTML interface to adding interactive features with JavaScript and styling with CSS, you now have the foundation to build a Chrome extension that can enhance everyday productivity and information management.
This journey through extension development has not only equipped you with specific skills for this project but also opened the doors to the vast possibilities of Chrome extension development. You’re encouraged to experiment further with this project. Perhaps you might want to add new features, like syncing notes to a cloud service, implementing reminders, or even integrating with other APIs.
The skills you’ve acquired here are just the beginning. Use them as a springboard to dive deeper into the world of web development and Chrome extensions. Happy coding, and may your creativity lead you to develop more amazing tools!
Digital Designer, blog writer and also a tech enthusiast.
He loves to write content for blogs, podcasts, design websites, logos, brochures, banners and anything that sends a message to an audience.
You can contact Daniele at the link below:





