1

I am new to Javascript as well as Chrome extension development. I was trying to open a tab when the user clicks on the extension button. This is how my popup.html looks like

<!DOCTYPE html>
<head>
<title> Qoogle Homepage</title>
<script type="text/javascript">
var newURL = chrome.extension.getURL('qoogle.html');
chrome.tabs.create({ url: newURL });
</script>
</head>
</html>

I have declared the tabs permission in my manifest.json and qoogle.html lays in the same directory. But when I click on the extension, nothing happens.

Now, I tried to include <script src="popup.js"></script> line into my popup.html and then wrote

var newURL = chrome.extension.getURL('qoogle.html');
chrome.tabs.create({ url: newURL });

inside the popup.js file. This works fine.

I don't want too many files in my folder. What could be the reason my script does not get executed from the HTML and works fine when added separately as a JS file?

Anonymous Platypus
  • 1,242
  • 4
  • 18
  • 47

1 Answers1

4

As stated in the Docs:

https://developer.chrome.com/extensions/contentSecurityPolicy#JSExecution

Inline JavaScript will not be executed

Check out this answer as well: https://stackoverflow.com/a/27913209/3052648

Community
  • 1
  • 1
MazzCris
  • 1,812
  • 1
  • 14
  • 20