I want to save the url link of the active tab, through a chrome extension, when an user clicks on the extension icon. The url should be saved in local storage, and should remain stored until the active window isn't closed. I am trying to save the url in an array tablink
Here's the manifest.json
{
"manifest_version": 2,
"name": "saveLink",
"version": "1.0",
"browser_action": {
"default_icon": "xyz.png",
"default_popup": "popup.html",
"default_title": "saveLink"
},
"permissions": [
"activeTab",
"storage",
"tabs"
]
}
Here's my popup.js
which contains the js code for popup.html
var tablink = [];
function getTabUrl(){
chrome.tabs.getSelected(null,function(tab) {
var len = tablink.length;
if(len == 0){
tablink[0] = tab.url;
}
else {
tablink[len] = tab.url;
}
console.log(tablink);
}
}
document.addEventListener("DOMContentLoaded", function() {
getTabUrl();
link.addEventListener('click', function() {
chrome.tabs.update({url: 'https://www.google.com/'});
});
});
Currently, the console isn't printing anything. Also, the extension has a button which redirects to the specified link(google.com), which was working fine before I wrote the code for saving tab links, but now isn't working. Please specify if anything more needs to be added.