It appears there is a problem with specifying the permission for the specific URL in Manifest V3, especially when dealing with query parameters. I can't get it to accept the url in any configuration.
here is my code. I am looking to build an extension to play an online streaming radio.
{
"manifest_version": 3,
"name": "NY Jewish Radio Player",
"version": "1.0",
"description": "Play New York Jewish Radio",
"permissions": [
"activeTab",
"storage",
"scripting",
"*://newyorkjewishradio.com/*"
],
"background": {
"service_worker": "background.js"
}
}
// content.js
// Function to interact with the play button
function interactWithPlayButton() {
const playButton = document.querySelector("body > div.radio_player > div > div.radio-player-controls > button.radio-play-pause > svg > g > path");
if (playButton) {
playButton.click();
}
}
interactWithPlayButton();
// popup.js
document.addEventListener("DOMContentLoaded", function () {
const playButton = document.getElementById("playButton");
playButton.addEventListener("click", function () {
// Find the active tab
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const activeTab = tabs[0];
// JavaScript code to interact with your player
const codeToExecute = `
// Find and click the play button on the website using the provided selector
const playButton = document.querySelector("body > div.radio_player > div > div.radio-player-controls > button.radio-play-pause > svg > g > path");
if (playButton) {
playButton.click();
}
`;
// Execute the code in the active tab
chrome.tabs.executeScript(activeTab.id, { code: codeToExecute }, function (result) {
// Handle the result if needed
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
} else {
console.log("Script executed successfully.");
}
});
});
});
});
// background.js
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (tab.url && tab.url.includes("newyorkjewishradio.com")) {
// Inject the content script into the tab
chrome.scripting.executeScript({
target: { tabId: tabId },
function: interactWithPlayButton
});
}
});
I tried rewriting several times. With a tab option, with a popup html and without.