Unable to resolve google-chrome-extension CSP error - google-chrome-extension

I am trying to create my first chrome extensions, here is my manifest.json
{
"name": "share2twitter",
"version": "0.1",
"manifest_version": 2,
"browser_action":{
"default_icon": "icon.png",
"default_popup": "index.html"
},
"background": {"page": "index.html"},
"permissions": [
"https://www.googleapis.com/*",
"tabs"
],
"content_scripts": [{
"matches": [ "http://*/*", "https://*/*" ],
"js": [ "jquery.min.js","index.js" ]
}],
"content_security_policy": "script-src https://www.googleapis.com/urlshortener/ 'self'; object-src 'self'; connect-src https://www.googleapis.com/"
}
https://github.com/kracekumar/share2twitter/blob/master/manifest.json and in debug mode I get the following error .
Refused to load script from 'https://www.googleapis.com/urlshortener/v1/url?callback=jQuery17108621194534935057_1344774835421&{%22longUrl%22:%22https://groups.google.com/a/chromium.org/forum/?fromgroups' because of Content-Security-Policy.
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.

Paths in source URLs are not allowed in Content Security Policy values. You'll need to use this in your manifest:
"content_security_policy": "script-src https://www.googleapis.com 'self'; object-src 'self'; connect-src https://www.googleapis.com"
A Chromium bug has been filed (and has some ongoing work) to better warn in this situation.

Related

Chrome Extension once disabled can't be enabled until reinstall

I created a chrome extension, which works fine when it is unpacked. Whether in Normal mode and Incognito mode too.
But when I pack the extension using "Pack Extension" feature of Chrome to pack the extension. Produced crx (packed extension) is once gets installed on Chrome, but when either
I disable the extension, or
Click on option "Allow in Incognito" http://i.imgur.com/zMxyN8T.png
Then, the Extension never gets activated until I remove the extension from chrome and reinstall.
On clicking the Enable checkbox it seems that it is activated but when you refresh the page, you'll see that extension is still deactivated, http://i.imgur.com/g09Ay7t.png
Any resolutions?
Edit:
I Saw the console:
Here is the error on clicking the checkbox:
Unchecked runtime.lastError while running management.setEnabled: Extension bdkngoljejekigejmcekcpghahpgljop cannot be modified by user.reportIfUnchecked # extensions::lastError:133handleResponse # extensions::sendRequest:78
Menifest:
{
"name": "TEST MAIN",
"version": "1",
"manifest_version": 2,
"description": "TEST MAIN",
"browser_action": {
"name": "Manipulate DOM",
"icons": ["images/icon.png"],
"default_icon": "images/icon.png"
},
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*" ],
"js": [ "js/jquery.min.js", "js/main.js" ],
"css" : ["all.css"],
"all_frames": true
}
],
"web_accessible_resources": [
"js/main.js"
]
}

Unable to update Chrome extension: Invalid version number in manifest: 0.1

I'm trying to update my Chrome Extension but when I upload the new one at the Chrome Web Store I get this error.
I tried version: 1.0, 0.1.1, 0.1.2.3 etc..
An error occurred: Failed to process your item.
Invalid version number in manifest: 0.1. Please make sure the newly
uploaded package has a larger version in file manifest.json than the
published package: 2.0.
{
"name": "Stylish Eve",
"description": "Fashion, Hairstyles, Outfits, Home Design and Architecture Blog Magazine",
"browser_action": {
"default_icon": {
"16": "icon-16.png",
"38": "icon-38.png",
"128": "icon-128.png"
},
"default_title": "Stylish Eve",
"default_popup": "labnol.html"
},
"manifest_version": 2,
"update_url": "http://clients2.google.com/service/update2/crx",
"content_security_policy": "script-src 'self' https://www.google.com; object-src 'self'",
"version": "0.1"
}
Try to set the version number to something larger than 2.0 (as it says in the error). 2.0 was probably the last version that you published and the next one has to be bigger.

webRequest permission malformed

I am trying to set up permission for Chrome so it can ask for webRequest.
However, if I add the permission like in the manual here http://developer.chrome.com/extensions/webRequest.html
{
"name": "My extension",
...
"permissions": [
"webRequest",
"*://*.google.com"
],
...
}
All I get from Chrome is
There were warnings when trying to install this extension: Permission
'://.google.com' is unknown or URL pattern is malformed.
Where is the error in the manual, what should I do differently?
Google is missing slash after the address. This works.
{
"name": "My extension",
...
"permissions": [
"webRequest",
"*://*.google.com/"
],
...
}
I... am not sure where to report the bug to google exactly.

chrome extension- manifest version 2 _locales issues

i'm trying to update my manifest version for my extension but it gave me this problem:
default locale was specified, but _locales subtree is missing.
this is my manifest.json file, can anyone tell me where is the problem and what can i do?
{
"name": "Selected Text",
"version": "0.1",
"manifest_version": 2,
"description": "Selected Text and some changes",
"default_locale":"en",
"browser_action": {
"default_title": "S. Text",
"default_icon": "online.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"chrome://favicon/",
"http://*/*",
"https://*/*"
],
{
"matches": ["http://*/*"],
"js": ["selection.js"],
"run_at": "document_start",
"all_frames": true
}
}
It sounds like you are missing the required _locales directory in your extension root. Since you are specifying a default_locale, you need to provide a _locales directory, inside of which lie your internationalization options. In your case, you would need to at least have a folder titled _locales/en, inside of which you have a messages.json file, inside of which you would set your specific parameters (see here for more information).
I got the same issue.
Its "default_locate": "en",.
But then there is still an error. So just leave it out.
Please check the file hierarchy. It should be something like below,
- manifest.json
- 📂 _locales 👈
- 📂 en
- messages.json
- 📂 es
- messages.json
- 📂 ...
- messages.json
Reference
chrome.i18n
manifest
messages.json
"default_locale":"en",
look at this code and think. you will get solution .

Why won't Chrome load extension with Content Security Policy that allows localhost?

I'm working on a Chrome extension and wanted to load scripts from localhost for development. So I updated the manifest file to have the following line:
"content_security_policy": "script-src 'self' http://localhost; object-src 'self'",
According to the doc on Content Security Policy, it's perfectly fine to use localhost or 127.0.0.1 without https.
However, I get the following (taunting) error message when I try to load the extension from chrome://chrome/extensions/:
Could not load extension from '/Users/Tim/Desktop/temp/test'. Invalid value for 'content_security_policy': Both 'script-src' and 'object-src' directives must be specified (either explicitly, or implicitly via 'default-src'), and both must whitelist only secure resources. You may include any of the following sources: "'self'", "'unsafe-eval'", "http://127.0.0.1", "http://localhost", or any "https://" or "chrome-extension://" origin. For more information, see http://developer.chrome.com/extensions/contentSecurityPolicy.html
To confirm the problem, you can create an empty directory with the following manifest.json file:
{
"name": "Example extension",
"description": "Trying to demonstrate a bug in Chrome",
"version": "0.1",
"homepage_url": "http://example.com",
"content_security_policy": "script-src 'self' http://localhost; object-src 'self'",
"manifest_version": 2
}
and load the directory as an unpacked extension. You should be getting the error. If you remove http://localhost or change it to https://localhost, it will load fine.
Am I missing something?
(NB: I'm using Chrome 22.0.1229.79)
Thanks!
The ability to add localhost to the CSP value was enabled by Chromium revision 151470, which is in Chrome 23 (currently in the dev channel, soon to be in the beta channel).

Resources