For a test case, I want to try to output the URL for the current tab. My manifest.json
{
"manifest_version": 2,
"name": "Chrome Extension",
"description": "MyExtension",
"icons": {
"16": "img/favicon.png",
"48": "img/48.png"
},
"version": "0.1",
"background": {
"scripts": ["js/content.js"],
"persistent": false
},
"permissions": [
"tabs", "https://*/*", "http://*/*"
],
"browser_action": {
"default_icon": "img/default_icon.png",
"default_title": "Get URL"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"all_frames": true,
"css": ["css/style.css"]
}],
"short_name": "GetURL"
}
And the code in my content.js
document.addEventListener('DOMContentLoaded', () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
alert(tabs[0].url)
});
});
The problem is that the URL is displayed only for the first current tab, but not for another tab that became active. I tried to changed currentWindow to lastFocusedWindow and to windowId but it did not solve the problem. Tell me what I'm doing wrong?