Chrome Extension: chrome.tabs.create callback function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Chrome Extension: chrome.tabs.create callback function



I was trying to call the chrome.tabs.create callback function in popup.js so that I could change the title of a tab. According to another StackOverflow question (chrome extension: callback function not getting called), I need to put the code in background.js in order to use the callback function.



However, I have tried this and it does not work. Even if I do not have the callback function (in background.js), the tab will not be created.



EDIT: updated code



part of popup.js


/* opens tabs if button is clicked */
groupButton.onclick = function()

/* opens the tabs */
for (var j = 0; j < group["tabCount" + i]; j++)

// cannot use callback function because popup is immediately closed upon
// tab creation, have to use background script
chrome.extension.getBackgroundPage().createTab(group, i, j);

// used to work in popup.js with no callback function
// chrome.tabs.create("url": group["tabUrls" + i][j], "active": false);




background.js


function createTab(group, i, j)

chrome.tabs.create("url": group["tabUrls" + i][j], "active": false, function(tab)

for (var k = 0; k < group["tabCount" + i]; k++)

var tabTitle = group["tabNames" + i][k];
console.log("create tab title: " + tabTitle);
chrome.runtime.sendMessage(tab.id, getTitle: tabTitle, function(response));

)



content.js


chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)

if (request.getTitle)

document.title = request.getTitle;

)





Ah yes 'group' was undefined, I've passed it into the function now. However, when I send info to the content script, the console says that "getTitle" is an invalid property.
– Marcus Martin
Aug 9 at 19:26









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS