Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use Javascript when creating a Chrome extension options page?

I tried following Google's example: https://developer.chrome.com/extensions/options.html

I immediately encountered the problem of the button and body trying to execute functions, so I attached listeners instead. Then, it's telling me that the options page isn't allowed to execute JS.

Either I didn't properly understand how to do that, or Chrome's documentation is entirely wrong.

How do you use JS in there? Or: can you point me in the direction of a proper tutorial.

like image 593
Rhyono Avatar asked Aug 17 '12 04:08

Rhyono


2 Answers

Check out this answer: Chrome tutorials - options page

"manifest_version": 2 forbids embedded scripts. Move all of the JavaScript to options.js and load it that way."

like image 198
Klevstul Avatar answered Oct 03 '22 13:10

Klevstul


You can't use inline JS with manifest v2.0 that is required for new extensions. That was possible with manifest v1 but not now. You have to reference script file to page. This issue if present on all extension pages.

<script type="text/javascript">JS CODE</script>

Is not allowed anymore. Use this instead.

<script type="text/javascript" src="FILENAME.js"></script>

Take a look at google code docs - manifest

like image 31
Aleksandar Toplek Avatar answered Oct 03 '22 13:10

Aleksandar Toplek