0
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Copy to Clipboard Extension</title>
    <script src="./Content.js"></script>
  </head>
  <body>
    <button id="copy-button">Copy Selected Text</button>
  </body>
</html>
{
  "manifest_version": 3,
  "name": "My Extension",
  "version": "1.0",
  "description": "This is my extension",
  "permissions": ["clipboardWrite", "activeTab","tabs","scripting"],
  "action": {
    "default_popup": "popup.html"
  }
}

function copyTextToClipboard() {
  chrome.tabs.executeScript(
    { code: "window.getSelection().toString();" },
    (selection) => {
      const text = selection[0];
      console.log("Selected text: ", text);
      if (text) {
        navigator.clipboard
          .writeText(text)
          .then(() => {
            console.log("Text copied to clipboard");
          })
          .catch((error) => {
            console.error("Failed to copy text: ", error);
          });
      }
    }
  );
}

is is showing me error Uncaught TypeError: chrome.tabs.executeScript is not a function

and i dont kknow how to cosnole.log() this extension even though i had tried console logging in the code but not sure where to see the result

  • 1
    In ManifestV3 it's chrome.scripting.executeScript and its [syntax is different](https://stackoverflow.com/a/67227376). Note that the popup is a separate window so it has its own separate devtools: right-click inside the popup and select "inspect" in the menu. – wOxxOm Feb 24 '23 at 13:17

0 Answers0