January 19, 2025
Albert Martinez
@albertdbio
Chrome Extension Debugging
Using chrome.runtime.lastError to debug Plasmo asset paths
Sometimes debugging feels more like detective work than coding. I recently ran into a case where Chrome notifications weren’t showing up in my Plasmo-based extension. I suspected a permissions problem, but everything checked out.
After a few hours of debugging I came across chrome.runtime.lastError
which you can use a such:
chrome.notifications.create({type: 'basic',iconUrl: 'icon.png',title: 'Notifications',message: 'Notifications are now enabled.'}, () => {const lastError = chrome.runtime.lastErrorif (lastError) {console.error('Last error:', lastError)}})
Sure enough, lastError
reported that my icon path was invalid. The fix was to import the icon properly:
import myIcon from "url:/assets/icon.png"chrome.notifications.create({type: 'basic',iconUrl: myIcon,title: 'Notifications',message: 'Notifications are now enabled.'}, () => {const lastError = chrome.runtime.lastErrorif (lastError) {console.error('Last error:', lastError)}})
And that was that—problem solved. The lesson? Whenever something silently fails in a Chrome extension, chrome.runtime.lastError
can pinpoint the exact cause. Debugging is all about noticing the subtle details that trip up our assumptions.