Chrome Extension: Event Page For New Bookmark Events - google-chrome-extension

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.

Related

Getting cookies on contextMenu tab instead of active window

So I explain my issue and lets see if someone knows what I'm doing wrong.
I am creating a chrome extension that adds an option in the context menu. As part of the action I need to fetch one cookie and with the value of the cookie, open a new tab.
My problem is seems to be with the Mac version (I cannot reproduce it on Windows, but I haven't tried other linux distros) that if the user has a normal window and an incognito window opened, if he has the focus on the incognito window, and does the right-click on the normal window to trigger the contextMenu action (MacOS doesn't change the focus), chrome tries to get the cookie from the incognito window and open the new tab in the incognito window, which is the one focused, instead of the window that received the right-click.
Any Idea on how to fix it?
(In order to reproduce, you need to Allow in incognito)
script.js
function openTab(info, tab) {
console.log(tab.url); // returns the clicked url, not the incognito
chrome.cookies.getAll({}, function(cookies){
console.log(cookies); // shows only the cookies of the incognito
// this will open the tab in the incognito window
chrome.tabs.create({
url: "https://www.example.com"
});
});
}
chrome.contextMenus.create({
"title":"Open tab",
"contexts":["link"],
"onclick":openTab
});
With the following manifest
{
"name": "Getting cookies context change",
"description": "Example of what goes wrong while getting cookie",
"version": "0.1",
"permissions": [
"contextMenus",
"cookies",
"activeTab",
"<all_urls>"
],
"background": {
"scripts": ["script.js"]
},
"manifest_version": 2
}

Scanning Text through a chrome extension to auto launch links

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.

Click make popup disapear

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.

Using console.log() in js [duplicate]

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.

Extension only works when Chrome starts

I am testing my Chrome extension by using the following codes:
chrome.tabs.create({url: "login_popup.html"}, function(tab){
chrome.extension.sendRequest({oid: tab.openerTabId});
});
However, a new tab was created only when Chrome started, but no tabs were created when I opened open a new page. Shouldn't the chrome.tabs.create be executed whenever a new page is loaded?
The manifest.json is:
{
"name": "minus_test",
"version": "1.0",
"background_page": "minus_test.html",
"permissions": [ "*://*/", "tabs" ]
}
Thanks!
No. background_page gets executed once when Chrome starts at which point it creates a new tab. If you want to create a new tab ever time a new window is opened you need to use the chrome.windows.onCreated listener.

Resources