Chrome Extensions only working for certain websites

so I am making a chrome extension that displays a box overlayed on the tabs displaying the current spotify song you are playing. I have gotten everything to work except for the fact that when I click on the tab to display the box, only certain websites like chatgpt and my own localhost show the box, with all other websites (like stackoverflow and youtube) not showing anything. Below, I’ve attached my manifest.json and script.js files which should have the necessary permissions to modify the tabs and the code itself but any advice and help would be appreciated. In the code below I attached some code ti display the error if the tab doesn’t allow the box and this is the error that appears:”Cannot access contents of the page. Extension manifest must request permission to access the respective host.” The amount of hello’s I have in this code is because of me using hello to display the box before I integrated the Spotify API so I apologize if that causes some confusion. Thank you.

manifest.json file
{
  "manifest_version": 3,
  "name": "Spotify Song Shower",
  "version": "1.0",
  "type": "module",
  "description": "A simple Chrome extension that displays the current song playing from Spotify in the top left corner of the window.",
  "action": {
    "default_popup": "index.html"
  },
  "dependencies": {
    "express": "^4.17.1",
    "node-fetch": "^3.0.0",
    "querystring": "^0.2.0"
  },
  "permissions": ["tabs", "scripting", "activeTab", "notifications"],
  "background": {
    "service_worker": "background.js"
  },
  "host_permissions": ["<all_urls>", "http://*/*", "https://*/*"],
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["script.js"]
    }
  ]
}

script.js file (the file that runs and displays the box)

async function addbox(TrackName) {
  // Creating and styling the box. It is on the top left of the screen and should show the current song playing
  const helloBox = document.createElement("div");
  helloBox.id = "hello-box";
  helloBox.style.position = "fixed";
  helloBox.style.top = "0px";
  helloBox.style.left = "0px";
  helloBox.style.padding = "5px 10px 5px 10px";
  helloBox.style.backgroundColor = "black";
  helloBox.style.color = "green"; // Font color of the text
  helloBox.style.zIndex = "1000";
  helloBox.style.borderRadius = "0 0 10px 0"; // Rounded bottom-right corner
  helloBox.style.fontSize = "16px";
  helloBox.style.textAlign = "center";
  helloBox.style.whiteSpace = "nowrap";
  helloBox.style.display = "inline-block"; // Size the box based on content width

  //console.log(typeof TrackName);
  //console.log(TrackName);
  helloBox.innerText = "Song: " + TrackName;
  document.body.appendChild(helloBox);
}
// When the button in index.html is clicked this is triggered causing the events inside to happen
document.addEventListener("DOMContentLoaded", () => {
  document.getElementById("showHello").addEventListener("click", async () => {
    chrome.tabs.query({}, (tabs) => {
      for (let tab of tabs) {
        // Loops through every tab that is open
        console.log("Testing track name: " + currentTrackName); // Logging in console current song playing
        chrome.scripting.executeScript(
          // Adds the box to the tab
          {
            target: { tabId: tab.id },
            func: addbox,
            args: [currentTrackName],
          },
          (results) => {
            // Returns console log on if box is added to tab or not
            if (chrome.runtime.lastError) {
              console.error(chrome.runtime.lastError); **// This is where all the error message is coming up from**
            } else {
              console.log("Script executed on tab ID:", tab.id);
            }
          }
        );
      }
    });
 });
});

New contributor

Saaketh Sodanapalli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật