document.addEventListener('DOMContentLoaded', () => { const startButton = document.getElementById('start'); if (startButton) { startButton.addEventListener('click', () => { console.log("Start button clicked"); chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { console.log("Active tab:", tabs[0]); // Inject the content script chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, files: ['content.js'] }, () => { // After injection, send the message chrome.tabs.sendMessage(tabs[0].id, { action: "initiateDownload" }, (response) => { if (chrome.runtime.lastError) { console.error("Error:", chrome.runtime.lastError.message); } else { console.log("Message sent to content script, response:", response); } }); }); }); }); } else { console.error("Start button not found"); } });