localStorage
and connect to external APIs or databases.👉 Add a new file background.js
to the root of your project folder and paste this code.
// background.js
console.log("💥 Hello from background.js");
👉 Add a new file content.js
to the root of your project and paste this code.
// content.js
console.log("💥 Hello from content.js");
Manifest files use JSON, which has a strict syntax. If you have issues then try checking your manifest code using jsonlint.com.
manifest.json
to reference the new files.chrome://extensions
.{
"name": "Explode the Web! Tutorial",
"description": "🦆",
"version": "1.2.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"]
}]
}
To find proof the extension is "working" and that the content script has loaded:
Content scripts are injected into each page, but you can also view messages from the scripts running in the background using DevTools:
chrome://extensions
and click on "Inspect views service worker".