I have constructed a Chrome extension which creates an additional local page (about:blank-based) in a separate tab with a data table relevant to the main page from which the extension script is run. One feature of this table is that it contains links which when clicked should change the focus back to the main page tab, simultaneously with changing the URL of the main page tab. I have used the chrome.tabs.highlight
function from the Chrome tabs API here in conjunction with a background.js
script to change the focus.
This has worked fine since I developed this function this spring. Today I notice that although the main page tab changes its location when the link is clicked, the focus is no longer shifted. Have the inner workings of the chrome tabs API been changed in any way recently? Current Chrome version is 76.0.3809.132 for Mac and my OS is 10.13.6.
Using alert commands (see code) I can verify that info about tab index is passed ok between background.js
and content.js
.
"tabs" is also included in the permissions in the manifest.json
file.
Here is a summary of the relevant code. Note that the attribute "goto" is used instead of "href"; this is for tecnical reasons which I believe are irrelevant here.
//background.js:
var replyObject = {};
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
switch(request.command){
case "changeTab":
var toTab = request.data;
chrome.tabs.highlight({tabs:toTab});
//alert("totab: " + toTab);
break;
case "getTabIndex":
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var currTab = tabs[0].index;
if (currTab) {
replyObject = {type:"tabIdIs",data:currTab};
//alert("currTab: " + currTab);
}
});
break;
};
sendResponse(replyObject);
});
//===================
//content.js:
//getting tab index info:
chrome.runtime.sendMessage({command:"getTabIndex"},function(reply){
if(reply.data != undefined){
mainTab = reply.data;
}
});
//changing tab:
$(sumBody).on("click","a.qlink",function(){
var sendObj = {command:"changeTab",data:mainTab};
window.location.href = $(this).attr("goto");
chrome.runtime.sendMessage(sendObj);//visa Inspera-fliken
});