2

Let me preface this with saying I have read and tried everything on this site about this so far.

I am trying to make a Google Chrome extension that needs to get some selected text from a page. I know that I cannot do this inline in my popup.html, so my first thought was to break it out into a JS file. When I tried to do this, I was not able to use any functions like getElementById. They just didn't work. I tried all the permissions, different variations on the function, and it appeared as though Chrome was sand boxing the files.

My next attempt was to enable inline with CSP. I am getting error messages like this one:

'content_security_policy': Ignored insecure CSP value
"'sha256-08fd8a0180576c8bf2b8652419b5b8f4820513e2cbc085c0335c665cfeabb190''sha256-0c57eb1c87ec4157d3551f15681b726e5aadd64b969c331b24ce8ce6df548005'"
in directive 'script-src'

and I am not sure the issue or how to fix it.

I just want to know if and how to enable inline with CSP, or if anyone has any ideas about how to get the selection to a variable that I can use

My Manifest.json:

{
    "name": "FirstUse",
    "version": "1.0",
    "description": "Find the First Use of something!",
    "browser_action":{
      "default_popup": "popup.html",
      "default_icon": "icon.png"
    },
    "permissions": ["storage", "contextMenus", "activeTab", "tabs", "clipboardWrite", "clipboardRead"],
    "content_security_policy": "script-src 'self' 'sha256-08fd8a0180576c8bf2b8652419b5b8f4820513e2cbc085c0335c665cfeabb190''sha256-0c57eb1c87ec4157d3551f15681b726e5aadd64b969c331b24ce8ce6df548005'",
    "background": {
        "scripts": ["background.js", "popup.html"],
        "persistent": true
      },
    "manifest_version": 2
  }
Michael Hawkins
  • 2,793
  • 1
  • 19
  • 33
  • 1) remove `content_security_policy` line, 2) remove `"popup.html"` from `"scripts"`, 3) use chrome.tabs.executeScript as shown [here](https://stackoverflow.com/a/34181338). – wOxxOm May 26 '20 at 05:23
  • I get an error: Error handling response: TypeError: Cannot read property '0' of undefined – Micah Robinson May 26 '20 at 19:58
  • It probably means you're trying it on a page like the empty new tab or a `chrome://` page. Extensions can't access those. Only web pages are supported. – wOxxOm May 27 '20 at 04:06
  • Oh my god. You are a life saver. I have been working on this for WEEKS. – Micah Robinson May 27 '20 at 05:47

0 Answers0