I'm using a chrome extension with a button in the popup.html that opens a new tab. The destination URL of the new tab holds the URL of the current (original) tab as a parameter.
For instance: when fired from http://stackoverflow.com/
, the new tab should have an URL like http://www.mydestination.com/index.php?url=http://stackoverflow.com/
Here's my js:
document.addEventListener('DOMContentLoaded', function (tab) {
document.getElementById('button').addEventListener("click", function(tab) {
chrome.tabs.create({url: 'http://www.mydestination.com/index.php?url=' + tab.url});
});
})
The new tab is opened perfectly, but the URL is http://www.mydestination.com/index.php?url=undefined
(url = undefined).
I reckon the manifest.json holds the right permissions:
{
"manifest_version": 2,
"name": "My project",
"version" : "1.7",
"browser_action": {
"default_icon" : "img/icon.png",
"default_title" : "My project",
"default_popup": "html/main.html"
},
"permissions": [
"tabs"
],
"icons": {
"16": "img/icon.png"
}
}
Any clues on how to get the url transported properly?