I’m working on a chrome extension and I need to get the event when the tab is closed so I can fire of an post to a server. This is what I have atm.
chrome.tabs.onRemoved.addListener(function (tabId) {
alert(tabId);
});
But I can’t get it to work. Anyone got any ideas?
Edit:
When I’m running it, it says
Uncaught TypeError: Cannot read property ‘onRemoved’ of undefined
Edit2: manifest.json
{
"name": "WebHistory Extension",
"version": "1.0",
"manifest_version": 2,
"description": "storing webhistory",
"content_scripts":[
{
"matches": ["http://*/*"],
"js": ["jquery-1.7.min.js","myscript.js"],
"run_at": "document_end"
}
],
"permissions" : ["tabs"]
}
You can’t use
chrome.tabsAPI in content scripts:source
What you need to do is to establish communication between content script and background page. Background page has access to
chrome.tabsAPI:source
Everything is in the first five paragraphs of content script documentation.