Debugging Chrome extensions #DevToolsTips
Key Takeaways
The video demonstrates how to debug Chrome extensions using DevTools, covering topics such as loading extensions, inspecting background contexts, debugging content scripts, and using breakpoints.
Full Transcript
[Music] foreign let me look for an extension to help me stay focused when reading documentation oh wow this Oliver Focus mode seems great let me install that oh hey Oliver what are you doing here oh hey jessalyn I'm here to help you get started with this extension and debug is needed along the way oh nice take it away so let me start by telling you what this extension does once you install this extension you can click the extension's action icon when browsing our developer docs to enter Focus mode we'll add some CSS to the page hiding a number of elements and letting you focus on the content cool how do you feel that is an extension a web application not quite they use very similar Technologies HTML CSS and JavaScript but they can be installed by a user from the Chrome web store and have access to special apis that give them additional control over the browser think of them as a way of extending Chrome to make it your own and if you've not built one before we have a number of samples which make for a great starting point just head to the link below I see hang on a minute I have installed the extension it doesn't seem to be working though um I'm sure it worked on my machine well let's debug it together and find out what went wrong first let's load the source code into Chrome I'll head to Chrome colon extensions enable developer mode in the top right and choose load extension I find the folder with my code and load it in ah I can see there's an error already I can click to view the errors here on the extensions page or click service worker to inspect my background context and see exactly what's happening in the console this looks like a typo and an easy fix I just need to make sure the method I'm calling actually exists aha that's how you debug an extension one question though do you need to reload the extension every time you make changes great question for some changes you don't but generally it's a good habit some changes are only picked up when you reload and it also makes sure any initialization logic you've changed can be rerun it's super easy you just need to click this reload button on the Chrome extensions page and you don't even need to close devtools also you might wonder why we're in a separate Dev tools here that's because we're inspecting the extension service worker which is independent of any specific page the UI should hopefully be familiar though I see while we are here is there anything else interesting absolutely on the memory panel I can make sure I'm not using too much memory I can even see what specific data is in memory to make sure there's nothing surprising hey look if I search for developer.chrome.com I can see one of the URLs we have as a variable there's a lot to explore here and we only have so much time today but I'd encourage you to take a look if it interests you oh and don't forget while devtools is open your service worker is kept alive and will never be terminated does it matter if the service worker is alive or terminated yes and no if you're stepping through some code it's helpful for the service worker to stay alive so you don't lose your place but if you want to fully test your extension from a user's point of view it's important to make sure it works correctly when the service worker has been terminated and then wakes back up so when you're testing lifetime Behavior specifically closing devtools can be a good idea I feel like we have learned a lot already somehow the app is still not working why Oliver why hmm maybe there's something wrong with a Content script content script yeah these are scripts injected by the extension into a web page they run directly inside a page although with some isolation from the main JavaScript environment I see let's set a breakpoint to debug our scripts while we're looking at a page in the extension section of developer.chrome.com let's open the sources panel and select the content scripts tab find your extension among the others and then find the script you'd like to debug this is the function that should be running let me add a breakpoint and then toggle the action it does seem to pause let's hover over the message variable ah there's a data property so I need to check if message.data is focused on and not just message let's fix that cool if you want to learn more about breakpoint debugging definitely check out my previous video on that a there is a warning message here what happened yeah devtools ignores content scripts by default which changes how they behave with certain features you can remove this file from the ignore list even better if you regularly debug different content scripts and extensions you can configure devtools to include all content scripts by default nice a small tip here if you frequently use the content scripts tab you can drag it to the front to access it quicker oh nice I honestly didn't know that oh well seems like we have fixed all the issues it's Oliver Focus mode working now I hope so let's give it a try shall we awesome it works let's check it works even if the service worker is terminated we can go to Chrome colon slash service worker Dash internals and terminate our service worker look it's still working I think our job here is done yay thanks for showing us how to debug extensions where can we learn more apart from this video sure you can go to this link to learn the basics of extensions great that's all for today have fun building extensions see you for the next step two tips ciao [Music] thank you
Original Description
Extensions are built on web technologies like HTML, CSS and JavaScript and let you extend Chrome to make it your own. In this video, Jecelyn and Oliver look at how DevTools can be used to debug extensions during development and give a few tips and tricks along the way.
Chapters:
0:00 Intro
0:43 What are Chrome extensions?
1:10 Enable dev mode & load unpacked extensions
1:35 View errors
1:55 Reload & refresh extensions
2:19 Inspect service worker
2:36 Debug memory
2:57 Beware of alive service worker
3:30 What are content scripts?
3:50 Debug content scripts
4:29 Configure to not ignore content scripts
4:50 Reorder Content scripts tab
5:01 Terminate service worker
5:25 Learn more
Resources:
https://goo.gle/oliver-focus-mode
https://goo.gle/chrome-extensions-samples
https://goo.gle/chrome-extensions-101
https://goo.gle/mv3-content-scripts
https://goo.gle/devtools-breakpoints
Questions? Tweet to us:
Jecelyn Yeen → https://goo.gle/jecfish
Oliver Dunk → https://goo.gle/oliverdunk_
Chrome DevTools → https://goo.gle/chromedevtools
Catch more DevTools Tips → https://goo.gle/DevToolsTips
Subscribe to Chrome for Developers → https://goo.gle/ChromeDevs
#DevToolsTips
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Chrome for Developers · Chrome for Developers · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
Web Directions Code 2015 round up
Chrome for Developers
Maintainable Code - HTTP203
Chrome for Developers
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
The Guardian - Supercharged
Chrome for Developers
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
The Future of JavaScript - HTTP203
Chrome for Developers
Data Binding 101 -- Polycasts #28
Chrome for Developers
The Guardian part 2 - Supercharged
Chrome for Developers
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
Binding to Objects -- Polycasts #30
Chrome for Developers
Player FM - Supercharged
Chrome for Developers
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
Jake Beats Wikipedia - HTTP203
Chrome for Developers
Supercharged Observers! -- Polycasts #32
Chrome for Developers
Jai's Web blog - Supercharged
Chrome for Developers
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
Google+ Performance Improvement Comparison
Chrome for Developers
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
Binding to Arrays -- Polycasts #35
Chrome for Developers
HTTP2 - HTTP203
Chrome for Developers
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
Call For Submissions - Supercharged
Chrome for Developers
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
Highlights from Chrome Dev Summit 2015
Chrome for Developers
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
How I made a scroll-scrubbed video portfolio fast (Next.js 15 + GSAP + canvas)
Dev.to · Pratham Sharma
5 Reasons HTML Is About to Change Frontend Development
Medium · Programming
5 Reasons HTML Is About to Change Frontend Development
Medium · JavaScript
copilot browser tools make the frontend reviewable
Dev.to · Paulo Victor Leite Lima Gomes
Chapters (14)
Intro
0:43
What are Chrome extensions?
1:10
Enable dev mode & load unpacked extensions
1:35
View errors
1:55
Reload & refresh extensions
2:19
Inspect service worker
2:36
Debug memory
2:57
Beware of alive service worker
3:30
What are content scripts?
3:50
Debug content scripts
4:29
Configure to not ignore content scripts
4:50
Reorder Content scripts tab
5:01
Terminate service worker
5:25
Learn more
🎓
Tutor Explanation
DeepCamp AI