# Content\_script doesn't load

**URL:** <https://discourse.mozilla.org/t/content-script-doesnt-load/57508>\
**Category:** Development\
**Created:** [April 8, 2020, 11:26am UTC](https://discourse.mozilla.org/t/content-script-doesnt-load/57508 "2020-04-08T11:26:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasfuranku](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rasfuranku/32/35998_2.png) [@rasfuranku](https://discourse.mozilla.org/u/rasfuranku)\
**Post date:** [April 8, 2020, 11:26am UTC](https://discourse.mozilla.org/t/content-script-doesnt-load/57508/1 "2020-04-08T11:26:03Z")

</div>

Hi all, I am new on Add-ons and have what it is probably a silly question, however, I haven’t been able to load any content\_script. I have tried to include the script in two ways, via the “manifest.json” with the “content\_scripts” properties and using the “browser.tabs.executeScript()” method from the script.js file under the browserAction folder.  
the current structure, manifest and script from where is injected of my project are as follows:

```
browserAction
|__index.html
|__script.js
|__style.css
background.js
content_script.js
manifest.json

```

manifest.json

```
{
	"manifest_version": 2,
	"name": "Highlight",
	"description": "Highlight text",
	"version": "0.0.1",
	"icons": {
		"64": "icons/icon.png"
	},
	"permissions": [
		"activeTab",
		"contextMenus"
	],
	"content_scripts": [
		{
			"matches": ["*://*.mozilla.org/*"],
			"js": ["content_script.js,"],
			"all_frames": true
		}
	],
	"background": {
        "scripts": [
            "background.js"
        ]
    },
	"browser_action": {
		"default_icon": {
			"64": "icons/icon.png"
		},
		"default_popup": "browserAction/index.html",
		"default_title": "Highlight"
	},
	"page_action": {
		"default_icon": {
			"64": "icons/icon.png"
		},
		"default_popup": "pageAction/index.html",
		"default_title": "Highlight"
	},
	"options_ui": {
		"page": "options/index.html"
	}
}

```

script.js

```
    function start() {
    function selectText() {
    let selectedText = '';

    if (window.getSelection) {
        selectedText = window.getSelection();
    } else if (document.getSelection) {
        selectedText = document.getSelection();
    } else if (document.selection) {
        selectedText = document.selection.createRange().text
    }
    
    console.log(selectedText.toString());
};

function onError(error) {
    console.log(error);
}

browser.tabs.executeScript({file: "../content_script/index.js"})
.then(selectText)
.catch(onError);

};
start();
```

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [April 8, 2020, 6:56pm UTC](https://discourse.mozilla.org/t/content-script-doesnt-load/57508/2 "2020-04-08T18:56:20Z")

</div>

I see you’re using \*.mozilla.org content scripts. Where are you testing? On [developer.mozilla.org](http://developer.mozilla.org)? If so, also make sure you’re not testing in a private window (or have permanent private browsing enabled).

Lastly, how do you decide if your content script ran?

---

<div class="post-metadata">

**Author:** ![sylvaing](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/sylvaing/32/19043_2.png) [@sylvaing](https://discourse.mozilla.org/u/sylvaing)\
**Post date:** [April 8, 2020, 7:03pm UTC](https://discourse.mozilla.org/t/content-script-doesnt-load/57508/3 "2020-04-08T19:03:01Z")

</div>

To add on what freaktechnik said, if you are trying this on one of the following domain listed at

> **[Content scripts - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts)**
>
> A content script is a part of your extension that runs in the context of a web page (as opposed to background scripts that are part of the extension, or scripts that are part of the website itself, such as those loaded using the

it will fail and the page will log a [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) error.

---

<div class="post-metadata">

**Author:** ![rasfuranku](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rasfuranku/32/35998_2.png) [@rasfuranku](https://discourse.mozilla.org/u/rasfuranku)\
**Post date:** [April 9, 2020, 1:40pm UTC](https://discourse.mozilla.org/t/content-script-doesnt-load/57508/4 "2020-04-09T13:40:40Z")

</div>

Thanks guys for your quick answer. The way I manage to made it work was removing “content\_scripts” property from the manifest and just inject the script from the browser action file. It works just fine for what I need. The documentation pointed was really useful.
