You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: 'Chrome Extension Using ReactJS and MongoDB'
3
-
sidebar_label: Chrome Extension Using ReactJS and MongoDB
2
+
title: 'Chrome Extension Using MERN'
3
+
sidebar_label: Chrome Extension Using MERN
4
4
authors: [khushi-kalra]
5
-
tags: [chrome extension, ReactJS, MongoDB]
5
+
tags: [chrome extension, web dev, React, Express, MongoDB, Node, UI]
6
6
date: 2024-06-13 23:23:23
7
7
hide_table_of_contents: true
8
8
---
9
9
10
-
# Chrome Extension Using ReactJS and MongoDB
10
+
# Chrome Extension Using MERN
11
11
12
12
Creating a Chrome extension can seem like a daunting task, especially when you're trying to combine it with technologies like ReactJS and MongoDB. When I first set out to build my extension, I found it challenging to find a perfect YouTube tutorial or blog post that covered everything I needed. So, I turned to StackOverflow and other resources to piece together my project.
13
13
14
+
You can always take help from my github repository: https://github.com/abckhush/Basic-Chrome-Extension
15
+
14
16
Here's a step-by-step guide based on my experience:
15
17
16
-
## Step 1: Create a React App
18
+
## Creating Frontend of the Extension
19
+
20
+
### Step 1: Create a React App
17
21
First, you'll need to set up a basic React application. You can do this using Create React App:
18
-
``bash
22
+
23
+
```bash
19
24
npx create-react-app my-chrome-extension
20
25
cd my-chrome-extension
21
26
```
22
-
Step 2: Change the Manifest JSON File
23
-
The manifest.json file is crucial for Chrome extensions as it contains metadata about your extension. Create a manifest.json file in the public folder with the following content:
27
+
28
+
### Step 2: Change the Manifest JSON File
29
+
The manifest.json file is crucial for Chrome extensions as it contains metadata about your extension. Update the manifest.json file in the public folder with the following content:
24
30
25
31
```json
26
32
{
27
-
"manifest_version":3,
28
-
"name": "My Chrome Extension",
29
-
"version": "1.0",
30
-
"description": "A simple Chrome extension built with React.",
33
+
"manifest_version":3,
34
+
"name":"Chrome Extension",
35
+
"version":"1.0.0",
36
+
"description":"My First Chrome Extension Using MERN",
31
37
"action": {
32
38
"default_popup": "index.html",
33
-
"default_icon": "icon.png"
39
+
"default_title": "Open"
34
40
},
35
-
"permissions": []
41
+
"permissions":[
42
+
"scripting"
43
+
]
36
44
}
37
45
```
38
-
Step 3: Add Height and Width to index.css
39
-
To ensure your extension has the proper dimensions, update the index.css file in the src folder:
46
+
47
+
### Step 3: Add Height and Width
48
+
To ensure your extension has the proper dimensions, update the index.css file in the src folder and add height and width:
40
49
41
50
```css
42
-
html, body, #root {
43
-
height: 600px;
44
-
width: 400px;
45
-
margin: 0;
46
-
padding: 0;
51
+
body {
52
+
min-width: 300px;
53
+
min-height: 200px;
47
54
}
48
55
```
49
-
Step 4: Change Rendering to BrowserRoute in App.js and Add Routes
50
-
To manage different views in your extension, you can use React Router. Install React Router:
56
+
57
+
### Check Point
58
+
To check if you have followed all the steps properly. You can go try to run the extension in browser.
59
+
1. Run `npm build` in the terminal.
60
+
2. Open Chrome and go to chrome://extensions/.
61
+
3. Enable "Developer mode" in the top right corner.
62
+
4. Click "Load unpacked" and select the build folder from your React app.
63
+
5. See if can see the default React page in the height and width you gave.
64
+
65
+
### Step 4: Change Rendering to MemoryRouter
66
+
This is the most crucial step. BrowserRouter is not supported for the Chrome Extensions, which is default in React applications. We are going to change that too MemoryRouter.
Add a .env file in the backend folder with your MongoDB connection string:
165
+
### Step 3: Add a .env file
124
166
125
167
```env
126
-
MONGO_URI=your_mongodb_connection_string
168
+
MONGO_URI= your_mongodb_connection_string
169
+
PORT= 5000
127
170
```
128
171
129
-
## Final Thoughts
130
172
Building a Chrome extension with ReactJS and MongoDB was a learning experience filled with challenges and triumphs. While finding the perfect tutorial was tough, the process of solving problems using StackOverflow and other resources was incredibly rewarding. I hope this guide helps you in your journey to create your own Chrome extension.
131
173
132
-
Feel free to leave any questions or comments below, and happy coding!
0 commit comments