I have a simple Chrome extension that I can't get to be triggered by a keyboard shortcut. My extension looks at a matching URL, extracts the customer ID from it, then appends that customer ID to a Tableau Online URL and redirects the page or opens a new tab to that page on Tableau Online.
My manifest.json and runtime.js files have:
manifest.js
...
"permissions": ["storage", "declarativeContent", "activeTab", "tabs"],
...
"commands": { "open_tableau_report":
{ "suggested_key": { "default": "Ctrl+Shift+Y" }, "description": "Open Tableau Report"}},
...
runtime.js
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.text) {
switch (msg.text) {
case 'open_tableau_report':
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
chrome.storage.sync.get(['tableauBaseUrl','vsExtTarget'], function(items){
let url = tabs[0].url;
let vsid = url.match(/https:\/\/foo.com\/customers\/detail\/([a-f0-9]{24})/)[1];
target = items.vsExtTarget;
tableau_base_url = items.tableauBaseUrl;
if (target == 'new') {
chrome.tabs.create({url: tableau_base_url + vsid}); // new tab
} else {
chrome.tabs.update({url: tableau_base_url + vsid}); // same tab
}
});
});
break;
default:
sendResponse('');
}
}
});
When I trigger the shortcut key combo I see this error in the Chrome DevTools I see the error:
Error in event handler: TypeError: Cannot read property 'query' of undefined
at chrome-extension://pdjmgncpljjageanemimmdfpdokdfodm/main.js:5:16
Having added "tabs" to the permissions I'm assuming that the Chrome extension simply doesn't have access to chrome.tabs
? How can I rework the code in runtime.js to be responsive to the keyboard shortcut? Thank you!!