This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Where to read console messages from background.js in a Chrome extension?
I am trying to write my first Google Chrome extension. All I am trying to do is is create an extension that writes a string, via console.log(), to the console when the extension's browser action icon is clicked.
Here is my manifest.json:
{
"name": "My Extension",
"description": "My Extension",
"version": "1.0",
"permissions": ["tabs"],
"background": {
"scripts": ["test.js"]
},
"browser_action": {
"default_title": "My Extension",
"default_icon": "icon.png"
},
"manifest_version": 2
}
And here is test.js:
chrome.browserAction.onClicked.addListener(function(tab) { console.log('testing'); });
I have the console open in Chrome but when I click my extension's icon nothing is displayed in the console. I've tried reloading the extension but it hasn't helped.
I am abviously doing something wrong.
Any advice would be much appreciated.
LT
Your script runs in the background page, so the message will be displayed in the background page's console.
Open the Extensions page.
Make sure that Developer mode is checked.
Under My Extension, click _generated_background_page.html to inspect it.
Click on the Console tab.
Related
This question already has answers here:
Can I hide my extension's icon by default?
(4 answers)
Closed 5 years ago.
I am creating a chrome extension. When the extension is added to chrome, then icon next to address bar is added also (browser action). My extension does not need any browser action. So, how can I avoid creation of this icon?
Edit: My manifest file:
{
"background": {
"persistent": true,
"scripts": [ "background.js" ]
},
"description": "This extension ...",
"manifest_version": 2,
"name": "Something",
"permissions": [ "webRequest", "webRequestBlocking", "http://*/*",
"https://*/*" ],
"version": "1",
"icons": {
"128": "msdos.png"
}
If your browser extension does not need browser_action, you can simply remove it from your manifest.json see: from https://developer.chrome.com/extensions/browserAction.
It will remove the icon next to the bar address.
More details about manifest.json: https://developer.chrome.com/extensions/manifest
If it does not work, do you mind to post your manifest.json
EDIT: As wOxxOm mentionned, since January 2016, Chrome shows all the icons of the web extension. So there is no way to hide it (except on the older version of Chrome).
This question already has answers here:
Accessing console and devtools of extension's background.js
(9 answers)
Closed 6 years ago.
My Chrome extension doesn't seem to execute console.log in any way. It skips it.
console.log works: I can open the Console, type console.log('test'); and it works. It works from other scripts, i.e. a JS script loaded in a HTML page locally, but not from my extension.
My background.js that I run through manifest.json below. It executes alert(), but not console.log
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, { file: "jquery-3.0.0.min.js" }, function() {
console.log('----');
alert('Hello!);
});
});
I've tried:
delete console.log, delete window.console and delete window[console] as suggested by Restoring console.log() and JavaScript console log in Magento, but no success.
loaded the extension in Incognito mode, with no other extensions loaded, but no success.
updated background.js to consist of only a single line - console.log('----'); - still doesn't work.
making sure that the console reports "All", not just errors.
My manifest.json:
{
"manifest_version": 2,
"name": "My Chrome Extension",
"description": "This extension will you save time.",
"version": "1.0",
"permissions": [
"http://*/*",
"https://*/*",
"tabs"
],
"browser_action": {
"name": "Click to start the extension"
},
"background": {
"scripts": ["background.js"]
}
}
The console for your extension is in a separate window.You can inspect your console.log() messages by:
Go to chrome://extension
Enable developer mode
Click on the "background page" link at the "Inspect views" line
The developer console for your extension will open here.
Credits to: Where to read console messages from background.js in a Chrome extension?
I'm pretty new at chrome extensions and am trying to make a simple one that automatically launches links in my emails. I am going to modify it a bit later on, but for now, this is all I am trying to do. How do I have a chrome extension automatically read the text of the current tab that I am on, or when I open emails if I can get that specific? I have a manifest file set up and currently can make the extension button launch a link, but I'd rather have this happen automatically, as I don't want to hit a button to launch a link when I could just click the link itself.
manifest.json
{
"manifest_version": 2,
"name": "MT task launcher",
"description": "This extension launches Task Links in emails",
"version": "1.0",
"background": {
"scripts": ["task.js"]
},
"browser_action": {
"default_icon": "icon.png",
"default_title": "Email Task Launcher"
},
"permissions": [
"activeTab"
]
}
task.js
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "http://www.reddit.com";
chrome.tabs.create({ url: action_url });
});
Take a look at Official Guide, for your purpose, I think you should use content scripts ( which are injected into current web page), then read the DOM and get all the links. To open the links, you can either call window.open() or by passing message then open them via chrome.tabs.create
There are two options to do that, it's either edit the local copy of the extension or to inject the call to the extension.
Inject code as a Content script, use the matching rules as defines in the manifest file
A background page file use the 'chrome.tabs.onUpdated' event. Also, use the 'chrome.tabs.executeScript' method to inject script.
I'm currently developping a chrome extension in order to watch youtube videos in a popup window while browsing an other website.
It works just fine, the problem is that if I click on a link or switch fullscreen app (Mac) the popup disapear, how can I make the popup bubble stay "for ever" ?
The manifest :
{
"manifest_version": 2,
"name": "One-Click Youtube",
"description": "Youtube on one click",
"version": "1.0",
"permissions": ["tabs" , "contextMenus"],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "ytplayer.html"
}
}
There is an always on top window api for apps. A demo is here: https://chrome.google.com/webstore/detail/floating-youtube/jjphmlaoffndcnecccgemfdaaoighkel
You cannot. The popup will always close and destroy the page when it loses focus.
This behavior is by design; you need a different UI, maybe open a window with type: "popup".
If and when window type "panel" becomes available (probably never), your question can be solved better.
I'm completely new to Chrome Extensions. I want the creation of a bookmark to trigger a xmlhttprequest. Right now, I'm just trying to get a new bookmark event to do a console.log and can't see what I'm missing.
Here is my manifest.json:
{
"manifest_version": 2,
"name": "Booky Desktop Integration",
"description": "Sends New Chrome Bookmarks To Your Booky Desktop.",
"version": "1.0",
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": [
"bookmarks",
"http://bookydesktop.com/"
]
}
Here is my js:
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
console.log("bookmark created");
});
What am I missing?
Your code works perfectly as written. You're probably not viewing the console for your background page. You need to:
Open chrome://extensions/ (or click "Extensions" in Chrome's "Settings" menu)
Ensure "Developer mode" is ticked in the top right
Open the console by clicking "_generated_background_page.html (Inactive)" in the "Inspect views" list under your extension
Each page in Chrome has its own console instance. You were looking at the consoles of ordinary web pages, instead of looking at the console for your background page.