DeveloperBreeze

Chrome Manifest V3 Development Tutorials, Guides & Insights

Unlock 1+ expert-curated chrome manifest v3 tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your chrome manifest v3 skills on DeveloperBreeze.

How to Create a Chrome Extension for Automating Tweets on X (Twitter)

Tutorial December 10, 2024
javascript css html

The popup.js file links the buttons in the popup UI to the actions in the background script. Paste the following code into popup.js:

document.getElementById("start").addEventListener("click", () => {
  chrome.runtime.sendMessage({ action: "start" }, (response) => {
    if (chrome.runtime.lastError) {
      console.error("[popup.js] Error:", chrome.runtime.lastError.message);
      document.getElementById("status").innerText = "Error: Could not connect to background script.";
      return;
    }
    console.log("[popup.js] Response:", response);
    document.getElementById("status").innerText = `Status: ${response.status}`;
  });
});

document.getElementById("stop").addEventListener("click", () => {
  chrome.runtime.sendMessage({ action: "stop" }, (response) => {
    if (chrome.runtime.lastError) {
      console.error("[popup.js] Error:", chrome.runtime.lastError.message);
      document.getElementById("status").innerText = "Error: Could not connect to background script.";
      return;
    }
    console.log("[popup.js] Response:", response);
    document.getElementById("status").innerText = `Status: ${response.status}`;
  });
});