Full Tutorial | Building a Chrome Extension in Typescript and Vite

  Рет қаралды 46,001

Train To Code

Train To Code

Күн бұрын

Make a browser extension in Vite, Typescript and React. This tutorial also gives you some background on how Chrome extensions work and how you can iterate on a chrome extension as you build it yourself.
#chromeextensions #vitejs #typescript #learncoding
Manifest File Schema - developer.chrome.com/docs/ext...
📺 Full Vite + Typescript course on Udemy
www.udemy.com/course/vite-dev...
🔗 More guides & articles
traintocode.com
💻 Github
github.com/traintocode
🗣️ Social Media
- / jamesjcharlesworth
- / jcharlesworthuk
00:00 Introduction
01:47 Chrome Extensions Explained
05:22 Empty Extension
06:59 Adding an Icon
08:04 Adding a Script
12:34 Adding a Popup
17:44 Vite + Typescript
30:48 Finished Product

Пікірлер: 119
@alexdin1565
@alexdin1565 2 күн бұрын
Nice video man! Short and to the point.
@fabianmerchan
@fabianmerchan 16 күн бұрын
Great tutorial, keep it up bro!
@traintocode
@traintocode 9 күн бұрын
Thanks, will do!
@vedbhanushali608
@vedbhanushali608 Ай бұрын
sir very helpful tutorial, thank you for great explanation, I have still one query how to do background service and content service to run on it ?
@robj3d3
@robj3d3 Ай бұрын
Mate, you are absolutely brilliant. Incredibly well taught and presented. Thank you so much for this!
@playagain4397
@playagain4397 9 ай бұрын
I had to play around few videos before I land on this, and it's bang on; explained so nicely with easy steps. Great tutorial! Thanks.
@user-vi1rd5uy7o
@user-vi1rd5uy7o 10 ай бұрын
Thank you so much, it's an amazing tutorial for Chrome extension!!!
@Ryguy12543
@Ryguy12543 3 ай бұрын
Awesome video. Thank you :) Very clear.
@omarelouafi
@omarelouafi 7 ай бұрын
Thanks for this quick and concise tutorial !
@davidc.2525
@davidc.2525 17 күн бұрын
Not even done yet but this is for sure the best chrome extension tutorial on KZfaq!
@traintocode
@traintocode 9 күн бұрын
Thanks!
@PaDSt3r
@PaDSt3r 6 ай бұрын
Wow life saver! I didn't realize I could pass state into the dom and always thought I was limited to using state in the popup
@MincongHuang
@MincongHuang 5 ай бұрын
Thanks for this great tutorial, it helped me initialize the plugin quickly and understand the structure of a plugin.
@traintocode
@traintocode 4 ай бұрын
You're very welcome!
@mikkun_
@mikkun_ 2 ай бұрын
Man this summarizes everything I've learned so far in creating chrome extensions. You earned a sub from me!
@traintocode
@traintocode 2 ай бұрын
Thanks so much!!
@bobsmithy3103
@bobsmithy3103 Ай бұрын
goated. Best typescript extension tutorial
@traintocode
@traintocode 9 күн бұрын
Haha thanks
@ipranay
@ipranay 6 ай бұрын
Very cool! Thanks for the tut!
@traintocode
@traintocode 5 ай бұрын
No problem!
@justin9494
@justin9494 10 ай бұрын
this is so well produced. You deserve more subs! Thanks man
@traintocode
@traintocode 10 ай бұрын
Thanks - that means a lot :)
@Immigrantlovesamerica
@Immigrantlovesamerica 4 ай бұрын
How is it well produced?? The video wouldve been great if the audio didnt cut out, or if the video wasnt cut in half. He also didnt upload the vite app to github like he said he would in the video.
@ArmanJindal-ls8yo
@ArmanJindal-ls8yo Ай бұрын
Awesome video! Thanks so much. Quick q: how would you pass state from the page context to the popup context? I love that we can easily pass from popup to page via the args function, but what way would you recommend to go from page -> popup. I want to have my popup react to the current page the user is on! Thanks :)
@hurdurstudy295
@hurdurstudy295 2 ай бұрын
this tutorial is amazing
@traintocode
@traintocode 2 ай бұрын
Thanks!!
@btechstuff
@btechstuff 6 ай бұрын
very helpful and clear
@traintocode
@traintocode 5 ай бұрын
thanks!
@olumideoni8101
@olumideoni8101 9 ай бұрын
thank you so much, Great video
@traintocode
@traintocode 9 ай бұрын
Glad it was helpful!
@tubemyren3038
@tubemyren3038 8 күн бұрын
I cant find the source code for the React/Typescript example.... you are missing some codelines in the video, but cant find the source code!
@cirExUAB
@cirExUAB 11 ай бұрын
Thanks, you really help me to understand how work with "two scopes" (extension and web). keep going!!!...
@traintocode
@traintocode 10 ай бұрын
Thanks, will do!
@baljinderbenipal5804
@baljinderbenipal5804 10 ай бұрын
Phenomenal tutorial James! This video has all the relevant information required for development and the iterative approach is extremely useful. The end product is awesome!
@traintocode
@traintocode 10 ай бұрын
Awesome, thank you!
@user-ik8ez8mw4j
@user-ik8ez8mw4j 6 ай бұрын
unbeliever you are doing such great job
@gamehubby
@gamehubby 5 ай бұрын
More of this but advance
@traintocode
@traintocode 4 ай бұрын
great feedback thanks
@donnieyang7453
@donnieyang7453 4 ай бұрын
Great! nice tutorial
@AdityaG.
@AdityaG. 7 ай бұрын
Thank you sir, this is the exact solution for my problem...😄
@mahmoudaboueleneen
@mahmoudaboueleneen 4 ай бұрын
Amazing video, so useful
@traintocode
@traintocode 4 ай бұрын
Glad it was helpful!
@user-xd3st6ig1n
@user-xd3st6ig1n 8 ай бұрын
Awesome!!
@traintocode
@traintocode 7 ай бұрын
Thanks!
@pavelsavelev2560
@pavelsavelev2560 5 ай бұрын
great video man , just wanted to say thank you.
@traintocode
@traintocode 4 ай бұрын
thanks!
@ronaldsupenieks803
@ronaldsupenieks803 Ай бұрын
Nice video man. What's missing in this is a hot module reload set up - something I'm trying to figure out. this way you don't need to keep running the build command but have your changes appear live in the extension
@jaybeatz8084
@jaybeatz8084 4 ай бұрын
it works bro thanks 😀
@traintocode
@traintocode 4 ай бұрын
No problem
@EvansRutto-kd8fw
@EvansRutto-kd8fw 9 ай бұрын
awesome ..👏
@dmitriyvainila4227
@dmitriyvainila4227 2 ай бұрын
Wonderful video! Thank you, mate. Subscribed for more :)
@traintocode
@traintocode 2 ай бұрын
Glad it was helpful!
@Morimove
@Morimove 20 күн бұрын
nice tutorila but i need to build everytime. do you have any solution for it?
@kunalukey5870
@kunalukey5870 7 ай бұрын
Nicely explained! subscribed ❤
@traintocode
@traintocode 4 ай бұрын
thanks!
@mrlectus
@mrlectus 3 ай бұрын
Any solution to the "I have to build the file all the time"
@wahibakamoulcode
@wahibakamoulcode 3 ай бұрын
Great video hope we see advanced videos like for example auth with supabase using the extension etc
@eliasbenjamin4228
@eliasbenjamin4228 2 ай бұрын
If you wanted to add a service-worker to the vite application, would it be in the public or src folder, and how would the manifest point to it? Thanks!
@traintocode
@traintocode 2 ай бұрын
This article might help but I've not done it so can't speak from experience dev.to/reeshee/how-to-bundle-your-custom-service-worker-in-vite-without-using-pwa-4nk
@jeswer9
@jeswer9 8 ай бұрын
Deserves way more views!
@Abcdef-hq3vf
@Abcdef-hq3vf 26 күн бұрын
I want to know how to make an extention which could be interacted by a website. In other words how to manage content.js and background.js console.log('Content script loaded'); const script = document.createElement('script'); script.src = chrome.runtime.getURL('inject.js'); (document.head || document.documentElement).appendChild(script); script.onload = () => { console.log('Inject script loaded'); script.remove(); }; window.addEventListener('message', function(event) { if (event.source !== window) return; if (event.data.direction && event.data.direction === 'from-page-script') { chrome.runtime.sendMessage({ type: 'CUSTOM_WALLET_REQUEST', payload: event.data.message }, (response) => { window.postMessage({ direction: 'from-content-script', message: response }, '*'); }); } }); THis is an example code
@keshav_dhiman
@keshav_dhiman 2 ай бұрын
howto implement background scripts?
@DelwarAhmedHabib
@DelwarAhmedHabib 6 ай бұрын
Just wow!. I was exploaring if it is possible to create extention with frameworks like react or svelte and found this. Thnks a lot.
@traintocode
@traintocode 4 ай бұрын
no worries thanks for commenting
@piotrs448
@piotrs448 3 ай бұрын
And how to read page document in extension?
@wellshubtube
@wellshubtube 9 ай бұрын
Thank you for this video but can you explain how I can pass a function state to the DOm?
@AutomobiliBeast
@AutomobiliBeast 9 ай бұрын
Dude dont stop the prod. You deserve a lot more subs than this. This channel is underrated
@traintocode
@traintocode 4 ай бұрын
hahaha thanks! My channel is growing steadily but I just like making videos
@maninalift
@maninalift 5 ай бұрын
When you get to using Vite, you switch to having javascript files that are referenced from an index.html file. This suits what Vite expects, and allows Vite to use the index.html as the entry point, but for most chrome extensions, you will want to have possibly multiple javascript entry points that are referenced from your manifest.json and not from an html file. Is there a way to do this? I'm tempted to skip Vite and just use tsc directly to build. EDIT: I gave up too easily looking for an answer. It looks like it's actually quite easy. I haven't tested this yet, but something like: javascript // vite.config.js import { defineConfig } from 'vite'; export default defineConfig({ build: { rollupOptions: { input: { page: 'src/page.ts', options: 'src/options.ts', worker: 'src/worker.ts', // Add more entry points as needed }, }, }, });
@EpicKeyz
@EpicKeyz 11 ай бұрын
Hey, thanks for the tutorials. I'm just starting to learn how to code my own Chrome extensions and I really enjoyed your detailed step-by-step guide! Also, I wonder how do you type so fast? Or did you just record a coding video and then recorded your explanations?
@traintocode
@traintocode 10 ай бұрын
Thanks! And yes I recorded the typing separately. Everything is a lie
@KryptechOfficial
@KryptechOfficial 8 ай бұрын
I was wondering the same thing, until I some him "typing" with his hands off the keyboard 😂 It's a good idea!
@MarcelDiane
@MarcelDiane 3 ай бұрын
What program are you using at the beginning?
@rfgonzalezweb
@rfgonzalezweb 7 ай бұрын
hi, great tutorial, I have a question, let's say I want to use the chrome.storage.sync.get API inside a useEffect in my App.jsx file so I keep synced my service-worker and my popup, when I run npm run dev, react does not have access to the chrome API, how can I access it to keep emulating my chrome extension in dev like it were a standalone react app?
@eliasbenjamin4228
@eliasbenjamin4228 4 ай бұрын
I'm wondering the same thing!
@ivodelev9794
@ivodelev9794 3 ай бұрын
there is beta vite plugin
@goldenboy3627
@goldenboy3627 4 ай бұрын
if you can make a tutorial of automating clicking element selectors while the user is opening another tab while its performing the actions in the background with no interruptions would be very helpful i would even subscribe.
@traintocode
@traintocode 4 ай бұрын
You sir have a high price for clicking subscribe but it's a great idea thanks!
@ritavdas7570
@ritavdas7570 9 ай бұрын
Great tutorial , but one part I didn't understand is you told me that we need the *Content Script* to actually change the content of the page we are interacting with. But here you directly modified that in the same file where we were running that popup. One more thing why did you clear the service worker file ?
@LucianoMendes
@LucianoMendes 4 ай бұрын
Hi man, wanderful video, I love it. Can you help me, please? I have a extension built with Vanilla JavaScript and it rund when the page load, I followed your video but I can't do it run when the page load, only when clicked. How can I do that?
@idle.observer
@idle.observer 4 ай бұрын
I have spent over 5 hours just loading unpacked extension files. I am using Linux (PopOS) finally with help I found the issue. Because of portal bugs, if your source code is under home, it won't see it. Even if you click the button and select the directory, nothing changes. Move your source code under another directory like Documents, instead of Home. If the button still the button still does not work, just drag the directory (folder) and drop it to the extensions page. It should work.
@ericborder5996
@ericborder5996 8 ай бұрын
I still feel some gap between using chrome extensions from the scratch and with vite installation, but anyway this video helped me get started, thanks!
@minaamir3056
@minaamir3056 8 ай бұрын
okay, So where i should put my background file then??
@TheDemoded
@TheDemoded 9 ай бұрын
please share the whole project. due to screen capturing issues it's unclear in some parts
@traintocode
@traintocode 9 ай бұрын
Absolutely! Here is it on GitHub github.com/traintocode/sample-projects/tree/main/simple-chrome-extension
@oleholgerson3416
@oleholgerson3416 8 ай бұрын
@@traintocodeThe typescript + vite part seems to be missing.
@markh9646
@markh9646 8 ай бұрын
Hey @@traintocode Could you send a link to the code that includes the ts + vite section? Seems a lot of the code is off screen it's difficult to follow. Thanks!
@symbi21
@symbi21 4 ай бұрын
so where can i found the source code of the vite? onChange code is half in the video
@traintocode
@traintocode 4 ай бұрын
Hi! source code is here: github.com/traintocode/sample-projects/tree/main/simple-chrome-extension
@rahulgupta373
@rahulgupta373 2 ай бұрын
18:55 why i cant listen anything 😕??
@davidc.2525
@davidc.2525 17 күн бұрын
I was confused too. Thought it was my airpods haha
@jianjunxiao5779
@jianjunxiao5779 5 ай бұрын
how to write a content.ts and then produce a content.js in dist
@traintocode
@traintocode 4 ай бұрын
Run "tsc" to compile the .ts to .js. Or use a build tool that does this as part of the build process, such as Vite
@justin9494
@justin9494 10 ай бұрын
no hot reload?
@traintocode
@traintocode 10 ай бұрын
There are libraries that claim to make this possible but I just don't have experience using them github.com/xpl/crx-hotreload
@AndreiDamian
@AndreiDamian 7 ай бұрын
Nice introduction! Saving, running npm build, reloading the extension, reloading the page (maybe this is somewhat optional) seems to be very tedious. It would be nice to have at least some of these steps automated. Also showing some more errors, e.g. in background scripts and how to debug them would be useful for beginners.
@CaleyHamiltonProjects
@CaleyHamiltonProjects 5 ай бұрын
Can you do a tutorial for a side panel chrome extension
@traintocode
@traintocode 4 ай бұрын
What do you mean by "side panel"? Like some UI that gets injected into the actual page or the popup when you click the extension?
@CaleyHamiltonProjects
@CaleyHamiltonProjects 4 ай бұрын
@@traintocode No it's a newer chrome api which persists across page navigation and page changes. I can't post links because the last comment I did that got deleted Just look up "side panel chrome api" to see the api docs and search the same on youtube to see how it looks
@CaleyHamiltonProjects
@CaleyHamiltonProjects 4 ай бұрын
@@traintocode This is my 3rd time trying to reply to this post. Idky it keeps getting deleted. The side panel chrome extension is a newer api which persists across page reloads, navigation, and tab changes. I would post a link but I don't want the reply to get deleted a 3rd time. Just look it up on google to see the api docs and look on youtube to see the UI in action.
@CaleyHamiltonProjects
@CaleyHamiltonProjects 4 ай бұрын
@@traintocode This is my 4th time trying to reply to this post. Idky it keeps getting deleted. The side panel chrome extension is a newer api which persists across page reloads, navigation, and tab changes. I would post a link but I don't want the reply to get deleted a 4th time. Just look it up on google to see the api docs and look on youtube to see the UI in action.
@CaleyHamiltonProjects
@CaleyHamiltonProjects 4 ай бұрын
@@traintocode This is my 4th time trying to reply to this post. Idky it keeps getting deleted. The side panel chrome extension is a newer api which persists across page reloads, navigation, and tab changes. I would post a link but I don't want the reply to get deleted a 4th time. Just look it up on google to see the api docs and look on youtube to see the UI in action.
@Stericcc
@Stericcc 6 ай бұрын
i love u
@traintocode
@traintocode 4 ай бұрын
giphy.com/gifs/queue-megamind-metro-man-e5nATuISYAZ4Q
@pavelgrishin
@pavelgrishin 7 ай бұрын
9:51 this leads to anonymous function error
@traintocode
@traintocode 4 ай бұрын
The full source code is here on Git I may have copied something wrong in the video github.com/traintocode/sample-projects/tree/main/simple-chrome-extension
@idle.observer
@idle.observer 4 ай бұрын
could you fix? I can help
@DelPieroJoga10
@DelPieroJoga10 2 ай бұрын
only bad thing about this, its because uses react 😆
@tomkarho
@tomkarho 5 ай бұрын
What's the purpose of omitting react from the title? I came to this vid because I expected to see some pure typescript but instead I got a react tutorial instead. I feel deceived.
@chrisder1814
@chrisder1814 17 күн бұрын
g f hello
@masterjericho9026
@masterjericho9026 7 ай бұрын
Undetectable AI has released a chrome extension that will turn your essay to human written
@jonass_-yd3ww
@jonass_-yd3ww 3 ай бұрын
I do not understand the comments here about the video being "well produced". The guy rushes through everything and you constantly have to rewind and find precise timestamps, if you're uncertain about some pieces of the code. Then the guy all of a sudden talks about *the* terminal and from there on the video is a disaster. Sound is missing, one can't possibly understand what you're saying and you also don't help with setting everything up. In my years at university, I only learned about java script, html, and css, but never about the rest here, which is why this was very confusing. Also the "explanation" of Vite at the beginning of the section was not any helpful. Again: I do not understand, what video the writers of these comments watched, but for sure not the same as I did. Sorry for this much negativity, but these comments are not justified and also won't help the creator to improve. Like, at least watch the video before you upload it... Now after finishing the video: The example code isn't to find anywhere, which makes the parts that weren't visible in the video, impossible to figure out. Also, you tend to always do the important part on the bottom of the screen, which is just a terrible design choice, especially for tutorials. And once again: Comments like "Phenomenal tutorial" are really not justified. Your camera is literally blocking important pieces of the code, which are never shown. I seriously do not understand, how one can have anything positive to say about this video. It's really bad...
@traintocode
@traintocode 3 ай бұрын
All feedback is good feedback, thanks for taking the time to write this so I can make my videos better.
@kumarchandresh0
@kumarchandresh0 10 ай бұрын
Dude is managing two spellings of color in one file. Respect 🫡
@traintocode
@traintocode 10 ай бұрын
Unless the spec makes me spell it incorrectly I will go with "colour" whenever possible ;)
@iheanachovictor4884
@iheanachovictor4884 8 ай бұрын
Thanks a lot
Create a Chrome Extension with TypeScript React and Webpack
14:13
HTMX Sucks
25:16
Theo - t3․gg
Рет қаралды 111 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 79 МЛН
Самый Молодой Актёр Без Оскара 😂
00:13
Глеб Рандалайнен
Рет қаралды 8 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 113 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 10 МЛН
How to OVER Engineer a Website // What is a Tech Stack?
11:20
Fireship
Рет қаралды 2,3 МЛН
Coding a Chrome Extension with Claude-3.5-Sonnet (Part-1)
19:30
Eli Colussi
Рет қаралды 2,9 М.
This is Why Programming Is Hard For you
10:48
The Coding Sloth
Рет қаралды 713 М.
Build an AD BLOCKER Chrome Extension in Less Than 10 Minutes
8:06
Телефон-електрошокер
0:43
RICARDO 2.0
Рет қаралды 1,3 МЛН
Как распознать поддельный iPhone
0:44
PEREKUPILO
Рет қаралды 2,1 МЛН
Это Xiaomi Su7 Max 🤯 #xiaomi #su7max
1:01
Tynalieff Shorts
Рет қаралды 1,7 МЛН