Re: [crx] Unable to resolve CSP error

36 views
Skip to first unread message

CGS

unread,
Aug 13, 2012, 6:28:19 AM8/13/12
to Kr Ace Kumar Ramaraju, chromium-...@chromium.org
Hi,

I use this array for permissions and I have no problem accessing any web page:

    "permissions": [
        "background","tabs","<all_urls>"
    ]

In your case, maybe it will help to change "https://www.googleapis.com/*" to "<all_urls>" or, at least, to change to better match (your filter is 1 level, while you need to use 3 levels and may need access to http://groups.google.com).

I hope it will help.

CGS




On Sun, Aug 12, 2012 at 3:42 PM, Kr Ace Kumar Ramaraju <kracethe...@gmail.com> wrote:
I am trying to create my first chrome extensions, here is my manifest.json 
https://github.com/kracekumar/share2twitter/blob/master/manifest.json and in debug mode I get the following error . 


I looked into reference for mappy, stackoverflow.com and google official docs, nothing worked out. So I am asking help here.

Expected behaviour:
When I click on the extension , it tries to connect to goo.gl url shortner and displays alert box. 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/R-0zmcf4FbEJ.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Arul Gupta

unread,
Aug 13, 2012, 6:57:23 AM8/13/12
to chromium-...@chromium.org
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.

Arul Gupta

unread,
Aug 13, 2012, 7:00:30 AM8/13/12
to chromium-...@chromium.org
Also since now I'm using my own AJAX post request, you do not have to load the jquery in the index.html file.

kracekumar ramaraju

unread,
Aug 13, 2012, 7:43:34 AM8/13/12
to Arul Gupta, chromium-...@chromium.org
Well, thanks for the help, your code works, but when I replace with $.(ajax) it doesn't .


On Mon, Aug 13, 2012 at 4:30 PM, Arul Gupta <aru...@gmail.com> wrote:
Also since now I'm using my own AJAX post request, you do not have to load the jquery in the index.html file.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.



--
Thanks & Regards

"Talk is cheap, show me the code" -- Linus Torvalds
kracekumar

Arul Gupta

unread,
Aug 13, 2012, 8:04:42 AM8/13/12
to chromium-...@chromium.org
Thats what I was telling you.
I was trying to work with the $.ajax() method but I was having some problems as I explained in my earlier post. It may be due to the jquery library,

So I tried my own ajax method, and it works.
If you don't have any specific use of jquery other than the ajax request, you may consider using my method.

kracekumar ramaraju

unread,
Aug 13, 2012, 8:20:58 AM8/13/12
to Arul Gupta, chromium-...@chromium.org
Yes, I found some one had reported in jquery bug list and in 1.7.1 it was fixed, I d/l and started to use, still facing same issue. Anyways I will follow your code . 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
Reply all
Reply to author
Forward
0 new messages