Error on publishing Chrome Extension - google-chrome

I Have develop a Chrome extension but I'm stuck in the publishing step... When I try to upload my extension, I get this error :
An error occurred: Failed to process your item.
The manifest must define a version.
But I have defined a version... Here my manifest.json file :
{
"manifest_version": 2,
"name": "AccessID - RFID", // Nom
"version": "0.0.0.1", // Version
"version_name": "0.1 Beta",
"description": "Gestion RFID.", // Description
"icons": { ... },
"permissions": [ ... ],
"options_ui": { "page": ... },
"background":
{
"scripts": [ ... ]
},
"content_scripts" :
[
{
"matches": [...],
"all_frames": true,
"js": [ ... ],
"css" : [ ... ]
},
{
"matches": [ ... ],
"all_frames": true,
"js": [ ... ]
}
],
"web_accessible_resources" : [ ... ],
"page_action":
{
"default_title": "",
"default_popup": "",
"default_icon": { ... }
}
}
The most weird thing is that it's working great in developement mode. The extesnion is loaded and works well. So I actually don't understand what is going on.

manifest.json, as the name implies, is a JSON (JavaScript Object Notation) file and not a JavaScript source file.
The JSON format is deliberately simplistic and does not support any form of comments - so technically they are a syntax error. It's strange that it loaded normally for development, though.
Removing // comments will fix your issue. Other common issues include forgetting to put keys into quotation marks and leaving an extra comma - JavaScript would not complain about this since it's a valid ECMAScript object literal, but it's invalid JSON.
You can use JSON validators like JSONLint to catch errors like this.

Related

Which installed Chrome extension gives error alert?

On load of some page I getting alert (SyntaxError: "[object Object]" is not valid JSON)
But in anonymous mode all clear, so it given by Chrome extensions.
Is there a fast way to check what it is, other then going by exclusion method?
First you have to check your extension in chrome://extension and see if it shows any error on pointed location
enter image description here
if any error button shown here! than click on it to resolve error!
and [object object] is not valid json!
you can write only one value in these brackets []:
//its a right json format
"objects":["objects"]
and all of this json writes in this two brackets! {}
Here is Example of My Extension Manifest file!
{
"name": "Notify!",
"description": "A Google Chrome extension!",
"version": "1.7",
"manifest_version": 3,
"icons": {
"128": "/assets/icons/128.png",
"48": "/assets/icons/128.png",
"16": "/assets/icons/128.png"
},
"action": {
"default_icon": "/assets/icons/128.png",
"default_popup": "popup.html",
"default_title": "It's my title"
},
"background":{
"script": ["eventPage.js"]
//"service_worker": false
},
"content_scripts":[
{
"matches": ["http://*.google.com/*"],
"js": ["content.js","jquery-3.6.1.min.js"]
}
],
"permissions": [
"tabs",
"http://*.google.com/*"
]
}

ManifestV3: "invalid value for web_accessible_resources" or "resources must be listed" errors

This is my first attempt writing a Chrome extension. I added "web_accessible_resources": ["images/icon.png"] to manifest.json because I wanted to access the image from content script. After adding this line, I got the error "Invalid value for 'web_accessible_resources[0]'.
Could not load manifest." I have checked to make sure the file path is correct, where else could I be wrong?
Any help is appreciated.
{
"name": "Bookmark Checker",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"bookmarks",
"activeTab"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches":["https://www.google.com/search?*"],
"js": ["content/content.js"]
}
],
...
"web_accessible_resources": ["images/icon.png"]
}
The syntax for web_accessible_resources in Manifest V3 has changed:
"web_accessible_resources": [{
"resources": ["/images/icon.png"],
"matches": ["<all_urls>"]
}]
The matches key must specify where to expose these resources since Chrome 89.

Error processing manifest in firefox

I have developed a extension primarily focused on chrome which works but now i need that extension to work in firefox either so I checked by loading the extension by going to about:debugging page and loading temporary addons. Currently, I go an error. I got error something like this
Reading manifest: Error processing options_page: An unexpected
property was found in the WebExtension manifest.
Reading manifest: Error processing oauth2: An unexpected property
was found in the WebExtension manifest.
Reading manifest: Error processing key: An unexpected property was
found in the WebExtension manifest.
Here is what my manifest file looks like(I removed options_page)
manifest.json
{
"version": "1.0",
"name": "Browser Extension",
"manifest_version": 2,
"description":
"This extension allow the user to select the text and redirect to the application",
"page_action": {
"default_title": "Select Text",
"default_popup": "index.html"
},
"icons": {
"16": "img/browser16.png",
"48": "img/browser48.png",
"128": "img/browser128.png"
},
"background": {
"scripts": ["extension/js/background.js"],
"persistent": true
},
"content_scripts": [
{
"matches": [
"https://mail.google.com/mail/*/*",
"http://mail.google.com/mail/*/*"
],
"js": ["extension/js/jquery.min.js", "extension/js/content.js"],
"css": ["extension/css/main.css"],
"run_at": "document_end"
}
],
"permissions": [
"contextMenus",
"tabs",
"storage",
"webNavigation",
"notifications",
"cookies",
"identity",
"*://mail.google.com/mail/*/*",
"https://www.googleapis.com/*",
"https://*.googleusercontent.com/*"
],
"web_accessible_resources": ["img/browser128.png", "img/ios-link.svg"],
"oauth2": {
"client_id":
"114446495690-8ejpdgvmn8vc9pblteupetas.apps.googleusercontent.com",
"scopes": ["profile", "https://www.googleapis.com/auth/gmail.readonly"]
},
"key":
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnqFjzbt+LtejD1JhOyMUbejOHdLoemzryr+ZQHK2CEKuI0yVVYToFs7eNusH/hfxhnyF27G4BU8apsTc695EpVQGD0ANKdt6BjubRnA/4VcdkmfdD3D9nsdCc+fHkINRU5e05grfs/BETWW/JAUULduaNWGfhT7"
}
How do i resolve above issues to make it firefox compatible as well?

content script not being injected into extension html page

I have an extension that gets JSON data from a site for a list of characters and their resources when chosen from a menu. I'm using a single html page and trying to update it with javscript to modify the code for the menu. The only thing is that I can't get the content script injected/loaded into the html page.
When my extension is run, the path for the rem.htm file is shown as 'moz-extension://a02e52b1-e41d-4d28-844b-a8466a1dd67b/rem.htm' which gives an invalid error for the 'matches' key in the console.
What else can I use?
manifest.json:
{
"description": "Resource Manager for Path of Exile",
"manifest_version": 2,
"name": "Path of Exile Resource Manager",
"version": "1.0",
"content_scripts":
[
{
"matches": ["file:///rem.htm"],
"js": ["modify-page.js"]
}
],
"background":
{
"scripts": ["background.js"]
},
"browser_action":
{
"default_icon":
{
"16": "icons/rem_16.png",
"32": "icons/rem_32.png",
"64": "icons/rem_64.png"
}
},
"permissions":
[
"*://www.pathofexile.com/",
"webRequest",
"tabs",
"activeTab"
]
}
I figured it out. I didn't realize I had modify-page in a separate directory. I was then able to add '' to matches and it finally worked!

Auto Refresh on load page failure

I'm trying to create an extension for chrome that auto refreshes the page when the page load is failed for any reason.
my manifest.json:
{ "browser_action" : { "default_icon" : "icon.png"
},
"description" : "Making your first Google Chrome extension.",
"icons" : { "128" : "icon.png" },
"name" : "Tutorialzine Extension",
"version" : "1.0",
"permissions": [
"webRequest",
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>","http://*/*","https://*/*","*://*/*"],
"js": ["myscript.js"],
"run_at": "document_end"
}
]
}
myscript.js :
chrome.webRequest.onErrorOccurred.addListener(function details){
chrome.tabs.reload(details.tabId);
}
What am I doing wrong? Thanks in advance!
Content scripts don't have access to most of chrome.* APIs. It's clearly stated in the docs:
However, content scripts have some limitations. They cannot:
- Use chrome.* APIs (except for parts of chrome.extension)
You should use a background page or event page instead.
Also chrome.webRequest.onErrorOccurred.addListener(function details) is not a valid JavaScript code. function keyword shouldn't be there. I believe you copied this code from docs, but in docs this type of pseudo-JavaScript is used only to describe function definition (what types of arguments it expects, what type of values does it return etc.).