System:
Manjaro Linux
Chromium Version 104.0.5112.79 (Official Build) Arch Linux (64-Bit)
When the user clicks on this MV3 extension's action, it tries to download the file /text/Test.txt (packaged with the extension) to the Downloads directory:
https://github.com/GrippenDynamik/Download_Extension_File_MV3
manifest.json
{
"manifest_version": 3,
"name": "Download Extension File MV3",
"version": "1.0",
"action": {
"default_title": "Download Extension File MV3"
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"downloads"
]
}
background.js
function onChanged(downloadDelta) {
console.log("MV3", "b) onChanged", "downloadDelta", downloadDelta);
}
async function onCreated(downloadItem) {
console.log("MV3", "a) onCreated", "downloadItem", downloadItem);
}
function onClicked(tab, onClickData) {
chrome.downloads.download({
conflictAction: "overwrite",
filename: "Test.txt",
saveAs: false,
url: chrome.runtime.getURL("text/Test.txt"),
});
}
chrome.downloads.onChanged.addListener(onChanged);
chrome.downloads.onCreated.addListener(onCreated);
chrome.action.onClicked.addListener(onClicked);
/text/Test.txt
This is a test.
Results:
chrome.downloads.onCreated doesn't report any errors.
chrome.downloads.onChanged reports NETWORK_FAILED (and nothing else)
Am I doing something wrong, or it is not possible to download files packaged with an extension?
I know that I can
fetch() the file
turn the response into a data URL
download the data URL
But it would be nice if I could skip steps 1 and 2.
Simpler is better.
The problem is MV3, as usual.
https://bugs.chromium.org/p/chromium/issues/detail?id=1224027&q=downloads.download&can=2
"it doesn't work with chrome.downloads.download which doesn't support chrome-extension:// scheme"
I don't know if this is by design, or just another MV3 bug.
It works perfectly in MV2:
https://github.com/GrippenDynamik/Download_Extension_File_MV2
manifest.json
{
"manifest_version": 2,
"name": "Download Extension File MV2",
"version": "1.0",
"browser_action": {
"default_title": "Download Extension File MV2"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": [
"downloads"
]
}
background.js
function onChanged(downloadDelta) {
console.log("MV2", "b) onChanged", "downloadDelta", downloadDelta);
}
async function onCreated(downloadItem) {
console.log("MV2", "a) onCreated", "downloadItem", downloadItem);
}
function onClicked(tab, onClickData) {
chrome.downloads.download({
conflictAction: "overwrite",
filename: "Test.txt",
saveAs: false,
url: chrome.runtime.getURL("text/Test.txt"),
});
}
chrome.downloads.onChanged.addListener(onChanged);
chrome.downloads.onCreated.addListener(onCreated);
chrome.browserAction.onClicked.addListener(onClicked);
/text/Test.txt
This is a test.
Related
I've been learning how to make a Chrome extension and have been stuck on just adding an icon for a while now, I've copy pasted code that supposedly works but I keep getting this error:
Could not load icon 'icon16.png' specified in 'icons'.
Could not load manifest.
My code:
{
"manifest_version": 3,
"name": "extension",
"description": "test",
"version": "1.0",
"browser_action": {
"default_icon": "icon48.png"
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"content_scripts": [
{
"js": [
"test.js"
],
"matches": [
"https://www.test.com/*"
]
}
]
}
I've triple checked that every image is in fact a PNG and is of the right size. I have a single directory with manifest.json, test.js, and all three images (as well as a.prettierrc file, although I doubt that has any impact).
If I remove the icons part of manifest.json the extension works perfectly.
The error about not being able to load the manifest is likely related to:
"browser_action": {
"default_icon": "icon48.png"
},
which is from Manifest Version 2. The "browser_action" field should be changed to:
"action": {
"default_icon": "icon48.png"
},
For further reference see here: Action API unification
Chrome invalidate a valid manifest
While importing valid unpacked extension.
(manifest confirmed by https://manifest-validator.appspot.com/)
this error appears, and the extension do not get loaded.
Only one of 'browser_action', 'page_action', and 'app' can be
specified.
Manifest does not contain duplication of the neither mentioned in the error.
manifest.json
{
"applications": {
"gecko": {
"id": "addon#example.com",
"strict_min_version": "42.0"
}
},
"background": {
"scripts": ["jquery.js", "my-background.js"],
"page": "my-background.html"
},
"browser_action": {
"default_icon": "userInterface/browser_action_button/airplay_icon.svg",
"default_title": "LightDictionary",
"default_popup": "userInterface/browser_action_button/popup.html"
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
}
}
},
"content_security_policy": "script-src 'self' https://example.com; object-src 'self'",
"content_scripts": [
{
"exclude_matches": ["*://developer.mozilla.org/*"],
"matches": ["*://*.mozilla.org/*"],
"js": ["borderify.js"]
}
],
"default_locale": "en",
"description": "none",
"icons": {
"48": "userInterface/browser_action_button/airplay_icon.svg",
"96": "userInterface/browser_action_button/airplay_icon.svg"
},
"manifest_version": 2,
"name": "LightDictionary",
"page_action": {
"default_icon": {
"19": "userInterface/browser_action_button/airplay_icon.svg",
"38": "userInterface/browser_action_button/airplay_icon.svg"
},
"default_title": "LightDictionary",
"default_popup": "userInterface/browser_action_button/popup.html"
},
"permissions": ["webNavigation"],
"version": "0.1",
"web_accessible_resources": ["images/my-image.png"]
}
I have talked to Mozilla MDN maintainer on their IRC channel and I came to the conclusion, that the so called "cross-browser extension" manifest.json published on:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json
Was incompatible with Chrome, and only works on the Firefox browser due to:
Chrome has strict check on the manifest, and the way Chrome handles manifest differs from the way Firefox does it. Chrome is slow to adopt technologies that are supported by the Firefox.
So, the only way to make the manifest cross-browser compatible: is
to take quick manifest.json example suggested by MDN
load it into Chrome (chrome://extensions, Turn on developer mode, Load Unpacked)
check the errors and remove what is asked by the chrome.
Things to keep in mind:
Chrome does not support .svg format icons, this leads to not showing specified icon. While Firefox does support it, it is suggestive to not use svg for a cross browser extension.
Futher comment to read: https://hacks.mozilla.org/2017/06/cross-browser-extensions-available-now-in-firefox/#comment-21268
You can only have one of the properties that it specifies in the error.
Only one of 'browser_action', 'page_action', and 'app' can be specified.
You have both a browser_action property & a page_action property in your json object.
Remove one of these from the object to fix it.
I'm trying to create an extension that will prevent Chrome from downloading any files but I haven't been successful.
Here's my manifest
{"name": "Download Cancel",
"description": "Prevents Downloads",
"version": "0.1",
"background": {"scripts": ["background.js"], "persistent": false},
"permissions": ["downloads", "tabs", "http://*/*","https://*/*"],
"manifest_version": 2}
and background.js
chrome.downloads.onCreated.addListener(function(item) {
chrome.downloads.cancel(item.id);
alert("Downloading files is not permitted");
chrome.downloads.removeFile(item.id);
});
Can anyone offer some suggestions as to what I am doing wrong?
As you have already blocked downloading the file but to prevent it from crashing, you can check if the download has been completed or not and if yes, then remove it inside that if block.
chrome.downloads.onCreated.addListener(function(item) {
chrome.downloads.cancel(item.id);
if(item.state == "complete"){
chrome.downloads.removeFile(item.id);
}
});
Hi I have found other similiar questions on stackoverflow but none of them solved the purpose.
I want my chrome extension/app to be opened in a full tab like how POSTMAN extension is opened.
My manifest.json
{
"name": "Sample App",
"manifest_version": 2,
"version": "0.0.1",
"app": {
"background": {
"scripts": ["main.js"]
}
},
"icons": { "128": "icon.png" },
"permissions" : ["tabs" ]
}
My main.js (alias for background.js)
chrome.app.runtime.onLaunched.addListener(function() {
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) {
alert("Hi");
});
});
index.html is the file i want to load on opening the new tab.
My first time responding here on stackoverflow, please be gentle...
I discovered that it's much easier to add "launch" : { "local_path" : "index.html" } within the manifest.json file. See my sample manifest file below.
{
"manifest_version" : 2,
"name": "Hello World!",
"description": "My first Chrome App.",
"version": "0.1",
"app": {
"launch" : {
"local_path" : "index.html"
}
},
"icons": { "16": "icon.png" }
}
Keep in mind that this example is very basic, it has been stripped of some unnecessary information such as a background script but it should accomplish what you want.
http://developer.chrome.com/apps/first_app.html
chrome.app.runtime.onLaunched is only for Chrome apps, not extensions. The code for your background page will automatically run when the Chrome browser starts, so you can start directly with chrome.tabs.create(...).
Also, you need to include index.html and any resource included in your extension that the page will use in a web_accesible_resources section in your manifest.
I'm trying to made a simple google chrome extension using webRequest and onCompleted listener. When all the info is loaded i want to show an alert message, but is not working :(
Manifest
{
"name": "Test",
"version": "0.1",
"minimum_chrome_version": "10.0",
"description": "Test Google Chrome Extension",
"background_page": "background.html",
"permissions": [
"webRequest",
"*://*/*"
],
"content_security_policy": "default-src 'self'"
}
Background.html
chrome.webRequest.onCompleted.addListener(
function(details) {
alert(details.url);
},
{urls: ["*://*/*"]},
["requestHeaders"]
);
Solution
I solved the problem :)
I changed the line "requestHeaders" to "responseHeaders".
The solution was to change the line ["requestHeaders"] to ["responseHeaders"].
New Background
chrome.webRequest.onCompleted.addListener(
function(details) {
alert(details.url);
},
{urls: ["*://*/*"]},
["requestHeaders"]
);