I'm currently working on a Chrome extension that is meant to automatically close tabs when they are loaded if their URLs contain specific words or strings. I initially attempted to achieve this using the matches
statement in the extension's manifest.json
file. Unfortunately, this approach did not yield the desired result. Here is an excerpt from my manifest.json
file:
{
"manifest_version": 2,
"name": "Custom Tab Closer",
"version": "1.0",
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"background": {
"matches": [
"https://www.google.com/",
"https://example.com/login"
],
"scripts": ["background.js"],
"persistent": true
}
}
Furthermore, here is an overview of my background.js
script:
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
console.log('background script running');
chrome.tabs.remove(tabId, function() { });
}
})
Despite specifying that the script should only execute for pages containing URLs with 'google' and 'example.com', it seems to be running on all loaded pages. Any insights on why this might be happening?