I am trying to open a new tab after getting the current tabid so that I can pass a message from the newly opened tab to the previous one, I am doing this:
myscr.js:
var myvar = 0;
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
console.log(tabs[0]);
myvar = tabs[0].id;
//console.log(myvar);
});
var string_url = "getfilehandler.html/?" + "tabid=" + myvar;
window.open(string_url);
manifest.json:
"permissions": [
"tabs",
"contextMenus", "fileBrowserHandler"
],
"content_scripts": [
{
"matches": ["file:///home/user/Desktop/itproject/test.html"],
"js": ["myscr.js"]
}
],
My problem is when I am opening the file test.html
the browser nothing seems to be
happening!
the new window is opened when I am using just window.open(...)
in myscr.js
. I'm not really sure why it is happening! Any help would be greatly appreciated!
changes:
chrome.tabs.query({
active: true, // Select active tabs
windowId: chrome.windows.WINDOW_ID_CURRENT // In the current window
}, function(array_of_Tabs) {
// Since there can only be one active tab in one active window,
// the array has only one element
var tab = array_of_Tabs[0];
// Example:
var url = tab.url;
console.log(url);
// ... do something with url variable
});