Hey
I checked out your code on github.
I'm not really sure what you are trying to do.
Here are some things that I would like to point out:
1. If you provide a default popup for the browser action button, your listener will never be called.So you need to remove the default popup.
2. Whatever permissions you are using are correct.
permissions": [
"tabs"
],
In order to make cross origin ajax requests, you have to specify the other domain origins. Since we are only making a request to the
googleapis.com, this is correct.
3. Content security policy is required if you are loading any resources from web page.We are only making an AJAX request and that doesn't load any external resource from web.So we need not specify any specific CSP.
4. Why are you trying to insert any content scripts in all the pages? What you are doing right now will insert your index.js and jquery.min.js in every page that loads in the browser. When you insert index.js into any page, at that scope chrome API's are not available. Chrome APIs are only available in the extension. As a result there will be an error.
After fixing your manifest file, I could get the tweet() function to run on clicking of browser action button.But then there was some problem with the jquery ajax method. It was sending get request instead of post request. I could find this out because in the urlshortner API the only difference between the API to create short url and the API to get longer url from a short url, is that of POST and GET request respectively and the data that you send. I was sending POST request with longURL to be shortened, but it was giving an error of missing parameter shortURL. If I gave shortURL with POST request, it successfully returned longURL.
So instead of using jquery AJAX, I tried using my own AJAX POST request and it worked perfectly fine.
I have forked your github project and made the above changes.It works perfectly when you click on the browser action button.It shows alert boxes with the shortened url of current tab.
I have done all this based on your "expected behavior".You can access the forked code here:
If you are trying to achieve something else, let me know if I can help you.