Note that there are some explanatory texts on larger screens.

plurals
  1. POInjecting JS into local Extension file (in new tab)
    primarykey
    data
    text
    <p>I spawn a new tab using <code>chrome.tabs.create()</code> that tab goes to a page within the chrome extension. I then want to use <code>chrome.tabs.executeScript()</code> to inject a JavaScript file into the new tab (enter_content.js). However when I do this I am greeted with the error </p> <blockquote> <p>Error during tabs.executeScript: Cannot access contents of url "chrome-extension://adcfbbpepclgchodmdfbijpjhkgcamcg/enter.html". Extension manifest must request permission to access this host.</p> </blockquote> <p>My manifest looks like this</p> <pre><code>{ "manifest_version": 2, "name": "myExtension", "version": "1.0", "permissions": [ "contextMenus", "tabs", "*://*/*" ], "background": { "scripts": ["background.js"] }, "content_scripts": [ { "matches": ["&lt;all_urls&gt;"], "js": ["generic_content.js"], "all_frames": true, "run_at": "document_start" } ] } </code></pre> <p>What do I need to add to it to allow me to inject the code into the tab?</p> <p>//UPDATE</p> <p>To clarify, I have a context menu that when clicked opens a new tab and points it at the local file <code>enter.html</code>. the page just consists of an input box and a button. when clicked the button <em>should</em> send whats in the input box back to the background script using <code>chrome.extension.sendMessage()</code>. But it appears you can't inject a script from the extension into the page (which would allow it to communicate) nor can you directly via inline or seperate js file include anything within the chrome namespace in the <code>enter.html</code> code as this violates the default CSP, which if possible I would like to keep as-is.</p> <p>I have tried editing the CSP slightly but without any effect. I added <code>"content_security_policy": "script-src 'self' chrome-extension://adcfbbpepclgchodmdfbijpjhkgcamcg/; object-src 'self'"</code> as well as adding the specific pages at the end.</p> <p>I don't actually have any fully written pages as none of it works so I have no way to test what works in terms of message passing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload