Google Chrome Extension Alert on Click - google-chrome-extension

How do i display an Alert message instead of the pop up.
My goal is to launch a script when the user clicks the extensions icon. The pop up is unnecessary, in fact i would like to avoid letting the pop up to initiate all together. I want my extension to behave like the Gmail hyper link, but instead of opening a link, I want it to execute my script.

Take a look at the api.
You will want to remove the popup in your manifest and have a onClicked handler instead. It will look like this:
chrome.browserAction.onClicked.addListener(function(){
alert("stuff");
});
The important part is that you don't define a popup in your manifest as it prevents the event from firing.

Rather than a popup, I'm assuming you want to run a background script to listen for a browserAction event.
First, make sure you remove "default_popup": "popup.html" from your manifest.json. Then include the background script in "background".
Your manifest json should be something like this:
"browser_action": {
"default_icon": "image.png",
"default_title": "My Extension"
},
"background": {
"scripts": ["background.js"]
},

Related

Chrome background.js do not run unless manually click refresh icon in extension page every time the chrome first open

Recently I am developing an extension which listens to tab change and do some stuff according to it. Now I wrote my main logic in chrome.runtime.onInstalled.addListener in background.js. I used unpacked version for development. However, to make the extension work, I need to manually go to the extension page and click refresh icon every time when first open a chrome window, otherwise, it will not work. Is there a way to make the background.js run the code without manually click refresh button? I tried onStartup but it doesn't work out.
Although not ideal, you can make the background script run persistently if you modify your manifest.json to...
{
"name": "My extension",
...
"background": {
"scripts": ["background.js"],
"persistent": true
},
...
}
This is not recommended because background scripts can use a lot of resources so you should use something like chromes messaging API to run only on set/specific events.
If you need to look into changing your background script, look at this for more information.

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.

A Google extension without Omnibar Icon

This is probably a simple question, but I'm trying to create a Google extension without an icon, one that just runs in the background without a popup or anything. What would I put into the manifest to get this to happen?
Simply remove this from the manifest.json:
...
"browser_action": {
"default_icon": "icon.png"
},
...
Now the app will not appear in the top bar.

Chrome Extension: Event Page For New Bookmark Events

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.

Resources