Debugging Chrome extensions #DevToolsTips

Chrome for Developers · Beginner ·🌐 Frontend Engineering ·2y ago

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 Polymer Performance Patterns (The Polymer Summit 2015)
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
2 Polymer Power Tools (The Polymer Summit 2015)
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
3 Chrome Dev Summit 2014 – Chrome Case Studies
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
4 Web Directions Code 2015 round up
Web Directions Code 2015 round up
Chrome for Developers
5 Maintainable Code - HTTP203
Maintainable Code - HTTP203
Chrome for Developers
6 iron-ajax… wat?! -- Polycasts #26
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
7 The Guardian - Supercharged
The Guardian - Supercharged
Chrome for Developers
8 ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
9 #AskPolymer: Rob answers all the questions ever -- Polycasts #27
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
10 The Future of JavaScript - HTTP203
The Future of JavaScript - HTTP203
Chrome for Developers
11 Data Binding 101 -- Polycasts #28
Data Binding 101 -- Polycasts #28
Chrome for Developers
12 The Guardian part 2 - Supercharged
The Guardian part 2 - Supercharged
Chrome for Developers
13 The Future of Web Audio: with Chris Wilson and Chris Lowis
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
14 Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
15 Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
16 #AskPolymer: How do you make the show? -- Polycasts #29
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
17 Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
18 Binding to Objects -- Polycasts #30
Binding to Objects -- Polycasts #30
Chrome for Developers
19 Player FM - Supercharged
Player FM - Supercharged
Chrome for Developers
20 Where’s the Designer? #AskPolymer -- Polycasts #31
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
21 Jake Beats Wikipedia - HTTP203
Jake Beats Wikipedia - HTTP203
Chrome for Developers
22 Supercharged Observers! -- Polycasts #32
Supercharged Observers! -- Polycasts #32
Chrome for Developers
23 Jai's Web blog - Supercharged
Jai's Web blog - Supercharged
Chrome for Developers
24 Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
25 What about internationalization? #AskPolymer -- Polycasts #33
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
26 Developing for Billions (Chrome Dev Summit 2015)
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
27 Google+ Performance Improvement Comparison
Google+ Performance Improvement Comparison
Chrome for Developers
28 Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
29 Progressive Web Apps (Chrome Dev Summit 2015)
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
30 Instant Loading with Service Workers (Chrome Dev Summit 2015)
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
31 Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
32 Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
33 Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
34 Polymer - State of the Union (Chrome Dev Summit 2015)
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
35 Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
36 Introduction to RAIL (Chrome Dev Summit 2015)
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
37 DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
38 RAIL in the real world (Chrome Dev Summit 2015)
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
39 #ChromeDevSummit talks are up - W00T! -- Polycast #34
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
40 V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
41 Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
42 Owning your performance: RAIL (Chrome Dev Summit 2015)
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
43 HTTP/2 101 (Chrome Dev Summit 2015)
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
44 Leadership Panel (Chrome Dev Summit 2015)
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
45 Build Processes, Totally Tooling Tips (S2, Ep 5)
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
46 Accessibility (Chrome Dev Summit 2015)
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
47 Binding to Arrays -- Polycasts #35
Binding to Arrays -- Polycasts #35
Chrome for Developers
48 HTTP2 - HTTP203
HTTP2 - HTTP203
Chrome for Developers
49 Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
50 Call For Submissions - Supercharged
Call For Submissions - Supercharged
Chrome for Developers
51 Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
52 Testing AJAX with Web Component Tester -- Polycasts #37
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
53 Slack: Extended Xmas Special - Supercharged
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
54 Browser testing with Travis & Sauce Labs -- Polycasts #38
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
55 Optimize for production with Vulcanize -- Polycasts #39
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
56 Highlights from Chrome Dev Summit 2015
Highlights from Chrome Dev Summit 2015
Chrome for Developers
57 Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
58 Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
59 How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
60 Colors – DevTools Tonight #0 (Pilot)
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers

This video teaches how to debug Chrome extensions using DevTools, covering various topics such as loading extensions, inspecting background contexts, and debugging content scripts. By following the steps outlined in the video, viewers can learn how to effectively debug their Chrome extensions.

Key Takeaways
  1. Load the extension into Chrome
  2. Enable developer mode
  3. Inspect the background context
  4. Debug content scripts using breakpoints
  5. Test the extension after debugging
💡 DevTools can be used to debug Chrome extensions, and understanding how to use it can significantly improve the development process.

Related Reads

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
Up next
How to Speed Up Your WordPress Website with WP Rocket ⚡Tutorial 2026
Matt Tutorials
Watch →