Chrome Extension Service worker registration failed. Status code: 2 - google-chrome-extension

I'm making a Chrome Extension (using manifest v3) but when I try to "Load Unpacked" I get an error and all it says is Service worker registration failed. Status code: 2. Any help would be much appreciated!
manifest.json
{
"name": "Test",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
}
}
background.js
console.log('MY SERVICE WORKER')
Probably doesn't matter but I'm on
Chrome Version 109.0.5414.87 (Official Build) (x86_64)
and macOS BigSur

Related

CORS issue during HTTP request from background service worker in Safari web extension

Link to a repo with the Xcode project to test the issue: Test CORS Issue
This extension uses Manifest v3 and I have example.com in host_permissions
"host_permissions": [
"*://example.com/*"
]
When I run fetch("https://example.com") in background.js I get this error:
[Error] Fetch API cannot load https://example.com/ due to access control checks.
[Error] Failed to load resource: Origin safari-web-extension://e0b5d7c7-c079-484b-8825-44d261383cb6 is not allowed by Access-Control-Allow-Origin. Status code: 200 (example.com, line 0)
Tested in both Safari Version 16.0 (17614.1.25.9.10, 17614) and Safari Technology Preview Release 153 (Safari 16.0, WebKit 17615.1.4.1)
In the code I use chrome namespace (to test it in Chrome Browser) but I get the same issue with browser namespace.
If I run this extension without any change in Chrome Browser it works perfectly
(chrome://extensions/ → Load Unpacked)
Is there a way to avoid CORS issues without altering server access control settings?
Manifest v2 worked fine in this way.
Update 1:
The workaround for now to use background scripts (deprecated in v3) instead of background service worker.
Instead of this:
"background": {
"service_worker": "background.js"
},
Do this:
"background": {
"scripts": ["background.js"]
},
Update 2: How to make your extension work for both Chrome and Safari?
Chrome supports only
"background": {
"service_worker": "background.js"
},
Safari supports both service_worker and scripts but when you use service_worker it has this CORS issue.
So the solution is to ship extension with different values in background field.

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"
]
}

Using Dart in Chrome extension content script does not run?

I am trying to write a Chrome extension using Dart. So far everything goes well except for the content script --- the "main" function in the content script dart file does not seem to run.
To be more specific, first of all Dartium cannot be used since giving a dart file in the "js" rule in the manifest caused Dartium to complain; I next tried to compile the dart file (with csp: true) then make the manifest to include the compiled js file directly --- then I'm stuck, it seems that no matter what I try, the (compiled) "main" function just does not run.
Any suggestions?
Update:
The manifest file:
{
"manifest_version": 2,
"name": "Assistant",
"description": "Assists you with various tasks.",
"version": "1.0",
"minimum_chrome_version": "26.0",
"permissions": ["<all_urls>", "storage"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": [
"packages/browser/dart.js",
"dart_content_script.dart.js"
],
"run_at": "document_start",
"all_frames": false
}
],
"browser_action": {
"default_popup": "popup.html",
"default_icon": "bulb.png"
},
"background": {
"page": "background.html"
}
}
The content script dart file:
void main() {
print('main done');
}
The pubspec.yaml:
name: AssistentExtension
dependencies:
browser: any
chrome: any
dev_dependencies:
unittest: '>=0.10.0'
transformers:
- $dart2js:
csp: true
In the Chrome developer console, I can find the string "main done" meaning that the "main" function is indeed included in the compiled js, but nothing is printed meaning it is not run.
I had the same problem like yours. At that time I looked into the console logs, a log saying chrome package is missing (but i don't know what cause it), so I manually added it back to build folder, then it worked so I can see my logs written in main().
When I run test_ext that come with official chrome pub, I get a different error message in console log, again I solved it and then the test_ext sample is running well too.
So, my advise is take a look at the console log, it might help. You can open console for extension by right click on popup UI of extension and select 'Inspect Element' to open it.

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.

Google Chrome Content script on secure https page. Permissions are right

Sorry, found answer by myself (at the bottom of question)
I'm implementing simple google chrome addon (shows alert on android market, for now), and i'm facing with problems. What do i have:
Manifest (see below)
Icon.png
2 JS files (jquery and mine)
css file
permissions seem to be ok
Contents of each:
Manifest:
{
"name": "My first app",
"version": "1.0",
"description" : "My frist app",
"browser_action":
{
"default_icon": "icon.png"
},
"permissions":
[
"https://market.android.com/*"
],
"content_scripts":
[
{
"matches": ["https://market.android.com/*"],
"css": ["styles.css"],
"js": ["scripts.js", "jquery.js"]
}
]
}
My css file:
*
{
color:gray !important;
}
Scripts.js file:
$(document).ready(function() {
alert("!");
});
Jquery version is 1.7.1.
And now comes the sugar:
All items on android market are grayed. But no alert.
Thank you in advance, Nick.
OMG!
Just needed jquery before my script running. Sorry.
you need to load jquery in your manifest before your script

Resources