I want to create a Chrome extension that executes some code when the user reloads a tab e.g. by hitting the reload button. I'm attempting to do this via the webNavigation
API by listening for a transitionType
of reload
. However, I cannot seem to get it to work. Here's my code:
manifest.json
{
"manifest_version": 2,
"name": "Sample Extension",
"description": "Sample Chrome Extension",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"permissions":[
"webNavigation"
]
}
background.js
chrome.webNavigation.onCommitted.addListener(function(transitionType) {
if (transitionType.status == "reload") {
// code goes here e.g. a console log
console.log("You reloaded");
}
});
Any ideas where I'm going wrong? Also, should I put the executable code (shown here as an alert) in a separate .js file? Eventually it will play a sound.