So I'm trying to make an extension that on click opens a tab and goes to a page. The only thing I can make it do so far is open a tab and give me this error:
No webpage was found for the web address:
chrome-extension://hgjkkhjinhilcehaaldcnopaefinlfif/https://www.google.com/
Here is the manifest.json:
{
"name": "New App",
"version": "0.1",
"permissions": ["tabs"],
"manifest_version": 2,
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
},
"icons": {
"48": "icon.png"
}
}
Here is background.js
chrome.browserAction.onClicked.addListener
(function(tab)
{chrome.tabs.create({'url': chrome.extension.getURL('https://www.google.com/')}, function(tab) {})
}
)
What I was trying to do was open a new tab and go to a website in the browser action. Here is the answer:
Manifest.json
{ "name": "Funny Pictures",
"version": "0.1",
"manifest_version": 2,
"description": "Rick Roll all your friends!",
"browser_action": {
"default_icon": "funnyface.png"
},
"icons": {
"48": "funnyface.png"
},
"background":{
"scripts": ["background.js"]
}
}
background.js
chrome.browserAction.onClicked.addListener(function(activeTab) {
var newURL = "http://www.youtube.com/watch?v=oHg5SJYRHA0";
chrome.tabs.create({ url: newURL });
});
I swear I tried this previously, but that's how it goes I guess.
Related
I'm trying to build an extension to monitor the xhr portion of the devtools network tab. I decided to start as simple as possible with the background script below. I'm seeing no errors on loading the extension, but don't see any output in the console.
manifest.json:
{
"manifest_version": 3,
"version": "1.0",
"name": "Hello World!",
"description": "Learning how to make a chrome extension!",
"icons": {
"16": "images/puppy16.png",
"48": "images/puppy48.png",
"128": "images/puppy128.png"
},
"action": {
"default_icon": "images/puppy.png",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"host_permissions": [
"https://cnn.com/*"
],
"permissions": [
"webRequest"
]
}
In my background.js:
(function () {
chrome.webRequest.onCompleted.addListener(
function (details) {
console.log('HELLO THERE!!!!', details);
},
{ urls: ["<all_urls>"] }
);
}());
What am I doing wrong?
I'm building a chrome extension and I have commands set in my manifest.json file as follows:
{
"manifest_version": 2,
"name": "Project X",
"description": "Quick lanch Project X",
"version": "0.0.1",
"icons": { "128": "icon_128.png" },
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["activeTab"],
"background":
{
"scripts": ["popup.js"],
"persistent": true
},
"commands": {
"execute-browser-action": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "Toggle feature foo"
}
}
}
My question is: Is it possible to change the default and mac keys (Ctrl+Shift+Y) to something else, during runtime? Specifically decided by the user?
I created a small extension for Microsoft Edge. It offers a right-click context menu item on certain elements. However, I noticed that the extension icon doesn't show up in the context menu if I don't have the browser action icon in the address bar. (The "show next to address bar" option) Not even the default icon is shown, it's just completely blank.
My manifest.json:
{
"name": "",
"author": "",
"version": "1.0",
"description": "",
"browser_action": {
"default_icon": {
"20": "images/icon.svg",
"40": "images/icon.svg"
},
"default_title": "",
"default_popup": "popup.html"
},
"icons": {
"16": "images/icon.svg",
"32": "images/icon.svg",
"64": "images/icon.svg",
"128": "images/icon.svg"
},
"permissions": [
"contextMenus",
"storage"
],
"background": {
"scripts": ["js/background.js"],
"persistent": true
}
}
The relevant code in my background.js:
browser.contextMenus.create({
id: "",
title: "Image",
contexts: ["image"]
});
Windows version: 1809, Build: 17763.1
Edge version: 44.17763.1.0
It would be helpful if you let us know your Win10 and Edge versions.
However, this problem doesn't exist on Win10 build (17763.1).
Here is my manifest.json:
{
"name": "test",
"author": "",
"version": "1.0",
"description": "",
"icons": {
"16": "icons/icon.png",
"32": "icons/icon.png",
"64": "icons/icon.png",
"128": "icons/icon.png"
},
"permissions": [
"contextMenus",
"storage"
],
"background": {
"scripts": ["background.js"],
"persistent": true
}
}
Background Script:
browser.contextMenus.create({
id: "log-selection",
title: "Sample",
contexts: ["selection"]
}, onCreated);
function onCreated() {
console.log("Context Menu item was created");
}
Let us also know your Context Menu item creation code from Background Script.
Try to set explicit sizes in both manifest.json and in every browserAction.setIcon call may help you to solve the issue.
Example:
Manifest.json
{
"manifest_version": 2,
"name": "test",
"version": "0.0.1",
"author": "demo_user",
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_icon": {
"19": "icon.png",
"38": "icon2.png"
}
}
}
In JS file
browser.browserAction.setIcon({
path: {
"19": "testimage.png",
"38": "testimage.png"
});
Reference:
Edge: browserAction.setIcon not working when using a default icon with multiple sizes
You can try to make a test on your side and let us know about your testing result.
When I try to add some shortcut keyboard for my new extension Chrome, it doesn't work. When I try to check my command with this line :
chrome.commands.getAll(command => { alert(JSON.stringify(command)) })
The description and the name is displaying correctly, but the shortcut property render an empty string. I've tried so many shortcut, delete et re-install my unpackaged extension after that, it doesn't work always.
My manifest.json :
{
"manifest_version": 2,
"name": "myfirstext",
"version": "1.0.0",
"description": "blablabla",
"author": {
"name": "Ben Lmsc",
"url": "https://github.com"
},
"background": {
"scripts": ["js/main.js"]
},
"browser_action": {
"default_popup": "index.html"
},
"commands": {
"handle_my_key": {
"suggested_key": {
"default": "Ctrl+Shift+L"
},
"description": "Description of my shortcut"
}
},
"icons": {
"16": "img/LOGO_16.png",
"32": "img/LOGO_32.png",
"48": "img/LOGO_48.png",
"128": "img/LOGO_128.png"
},
"permissions": [
"http://*/*",
"https://*/*",
"notifications"
]
}
This my manifest:
{
"name": "Test",
"description": "Appliation",
"manifest_version": 2,
"version": "0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": { "16": "phone16.png", "256": "phone256.png" },
"browser_action": {
"default_title": "action description",
"default_icon": "phone20.png"
}
}
But when install this extension browser action icon is not shown.
Is there any problem?
Hoe can I show?
You are declairing a Chrome App, not an extension:
"app": {
...
}
Change the above block to:
"background": {
"scripts": ["background.js"]
}
(I.e. remove the wrapping app property, just leave background.)
Try this Manifest:
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"description": "Appliation",
"browser_action": {
"default_title": "Test",
"default_icon": "images/phone19.png",
},
"icons": {
"19": "images/phone19.png",
},
"background": {
"scripts": ["background.js"]
}
}