Chrome Extension - Console Log not firing - google-chrome-extension

I'm starting to learn to make my own Chrome Extensions, and starting small.
At the moment, I'm switching from using the alert() function to console.log() for a cleaner development environment.
For some reason, console.log() is not displaying in my chrome console logs. However, the alert() function is working just fine.
Can someone review my code below and perhaps tell me why console.log() isn't firing as expected?
manifest.json
{
"manifest_version": 2,
"name": "Sandbox",
"version": "0.2",
"description": "My Chrome Extension Playground",
"icons": {
"16": "imgs/16x16.png",
"24": "imgs/24x24.png",
"32": "imgs/32x32.png",
"48": "imgs/48x48.png"
},
"background": {
"scripts": ["js/background.js"]
},
"browser_action": {
"default_title": "My Fun Sandbox Environment",
"default_icon": "imgs/16x16.png"
},
"permissions": [
"background",
"storage",
"tabs",
"http://*/*",
"https://*/*"
]
}
js/background.js
function click(e) {
alert("this alert certainly shows");
console.log("But this does not");
}
// Fire a function, when icon is clicked
chrome.browserAction.onClicked.addListener(click);
As you can see, I kept it very simple. Just the manifest.json and a background.js file with an event listener, if the icon in the toolbar is clicked.
As I mentioned, the alert() is popping up nicely, while the console.log() appears to be ignored.

Try to open the "_generated_background_page.html" in extension page (chrome://extensions/)

Related

the click on chrome extension icon doesn't trigger chrome.browserAction.onClicked each time I clicked the icon

I'm developing a chrome extension and I want to detect every time a user clicks the extension icon.
I used chrome.browserAction.onClicked.addListener(function(){console.log('icon clicked')}) but I get the message one time only, when I click second time, third time, ... I get nothing. I don't know where is the problem
Below a portions of code of the extension:
manifest.json
{
"manifest_version": 2,
"name": "My ext",
"version": "0.1",
"browser_action": {
"default_title": "My ext"
},
"permissions": [
"tabs", "<all_urls>"
],
"background":
{
"scripts": ["background.js"]
} }
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
console.log("icon clicked")
// do something
});

How to remove the "read and change all your data..." warning for Chrome Extension?

I have created a Chrome extension and published it to the Chrome Web Store. I noticed with my initial version that when a user tried to install it they would get the warning that my extension could "read and change all your data on the websites you visit". I've changed and republished my extension so that I don't think that warning should be displayed, but it still gets displayed. Based on the information at https://developer.chrome.com/extensions/permission_warnings I don't think that message should be showing up. Below is what is in my manifest.json file. Any suggestions for how to make the warning go away?
{
"name": "Screen Recorder",
"description": "Record a video of your computer screen",
"version": "0.4",
"manifest_version": 2,
"icons": {
"16": "icon.png",
"128": "icon.png"
},
"background": {
"scripts": [
"background.js",
"ourrecorder.js"
]
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "receiver.html"
},
"permissions": [
"desktopCapture",
"tabCapture",
"notifications",
"unlimitedStorage"
]
}

To print console.log message in active window console instead of background..

I started building chrome extensions. Initially I started with a simple extension which prints the hello in background console. How can I print that in the active window console.
This is my manifest.json file
{
"manifest_version": 2,
"name": "example",
"version": "0.1",
"description": "My Chrome Extension",
"icons": {
},
"background": {
"scripts": ["js/background.js"]
},
"browser_action": {
"default_title": "My test Environment"
},
"permissions": [
"background",
"storage",
"tabs",
"http://*/*",
"https://*/*"
]
}
This is the content of my background.js file
a simple
console.log("hello");
Take a look at Content Script, you could use manifest.json injection or Programming injection to ensure your code run in the context of current webpage.
The former requires Message Passing or Storage to ensure communications between content script with background page;
while as for the latter, Try the following code in background.js
chrome.tabs.executeScript({code: "console.log('hello');"});

Script doesn't fully execute in Chrome Extension

Hopefully this is something simple. I'm testing a simple Chrome Extension script and it appears it'll execute part of the script, but won't complete it. For example, if I add an alert() to the beginning of a script, it will execute the alert. But if I place it after anything calling the chrome DOM object, it won't execute. Here's an example:
Will execute alert
alert("Test");
chrome.webRequest.onCompleted.addListener(function (request) { });
Will not execute alert
chrome.webRequest.onCompleted.addListener(function (request) { });
alert("Test");
Am I missing something?
Here is my manifest:
{
"background": {
"persistent": true,
"scripts": [
"scripts/libs/jquery.1.11.2.min.js",
"scripts/background.js"
]
},
"browser_action": {
"default_icon": "resources/icon.19.png"
},
"icons": {
"48": "resources/icon.48.png"
},
"manifest_version": 2,
"name": "Test",
"permissions": [
"<all_urls>",
"webNavigation",
"webRequest",
"webRequestBlocking"
],
"version": "1.0"
}
You are missing debugging it yourself.
Go to chrome://extensions/ and load the Dev Tools for your background page. You will see an uncaught exception that stops execution.
For webRequest events, you must include a filter argument to the addListener function.

chrome.bookmarks.create throws error "Cannot call method 'create' of undefined"

Hi I want to create a very simple extension for Chrome, that will create a bookmark with a single click to a default folder. So I created an extension using this service:
http://sandbox.self.li/bookmarklet-to-extension/
Now, I have this json.manifest file
{
"background": {"scripts": ["background.js"]},
"browser_action": {
"default_icon": "icon-128.png",
"default_title": "1ClickBookmark"
},
"name": "1ClickBookmark",
"description": " - Created with http://blog.self.li",
"homepage_url": "http://blog.self.li/post/16366939413/how-to-convert-bookmarklet-to-chrome-extension",
"icons": {
"16": "icon-16.png",
"48": "icon-48.png",
"128": "icon-128.png" },
"permissions": [
"tabs",
"bookmarks",
"http://*/*",
"https://*/*"
],
"version": "0.1",
"manifest_version": 2
}
where I added "bookmarks to permission"
and the javascript file:
(function(){
chrome.bookmarks.create({
'parentId': null,
'title': 'AAAAAAA',
'url': 'http://www.google.com/'});
alert("Bookmark added!");
})();
ParentId=null points to the root of "Other Bookmarks", that is fine.
The problem is that in Console I catch an exception:
"Cannot call method 'create' of undefined" for chrome.bookmarks.create
However, if I run just that script directly in the Background console it works just fine.
In Background console - work, in standard console - fails.
Why?
Any advice would be appreciated. Thanks
If you want your script to run in the context of other pages you must use content scripts. As it stands, your extension is only "running" on the background page. So your background page has access to the chrome.* object, but other pages will not until they are injected with a content script.
Have you tried to reinstall your extension after adding permission to manifest.json?

Resources