is it possible to launch an extension from a website? - google-chrome-extension

Had a qq: is it possible to launch an extension (that is already installed) when someone clicks on a link ?
For example, let's say on my website I have a button that says "click here to launch the extension". After they install my chrome extension, when a user clicks on this button, could the extension launch? (e.g.- the popup to open).
The goal is this: I have an extension that acts like a search bar. I also have search on the website, but I wanted it to search using the extension instead of the website if a user chooses to.
Thanks for any info,
Y

If you are asking for a way to programmatically open the extension's popup, then you will be disappointed (as it cannot be done).
If it serves your purpose, you could do something like this:
Have your extension inject a content script into your webpage.
Have the content script bind to a button's click event.
When the button is clicked: Pass some parameters to the extension's background page, let the extension perform the search and send the results back to the webpage.

Related

Using chrome extension open tab and allow auto login

In popup.html, I am having one submit button. Clicking on that button, I want to open url in new tab and pass username-password so that user can auto login to the website.
I don't want to use manifest's background and content_script.
I want to do it in normal popup.js which is included in popup.html. Is there any way to do that?
Thank you,
Trupti

Load/run/execute Chrome extension in new tab

Is there a way to run/execute a Chrome Extension in a new tab/window by loading the extension's code in that new tab or window?
Right now, the only way I know to get "free hosting" from Google for my Chrome extension, is to use the popup window as my main application window. That works fine, except for the fact that the popup window will close if you click on a different tab. So I think I need a different type of window as my main application window.
My only guess, is that you could set the window.location of the new tab to something like chrome://extensions/<my-extension-id> but that doesn't seem to work.
Can anyone alleviate my confusion? How to create a runtime for a Chrome app that isn't the popup, but isn't a native app, and isn't hosted by some web server other than Google's servers?
One thing I was thinking of was something like this:
https://gist.github.com/danharper/8364399
holy crap that was harder than it needed to be.
So you eventually end up at a url like this:
chrome-extension://<your-extension-id>/dist/index.html
to programmatically load a new tab or window, use this code in your background script:
chrome.tabs.create({url: chrome.extension.getURL('dist/index.html')});
in my case my app page, is located at dist/index.html, whereas my popup page will live at popup.html.
So the popup window looks something like this:
x Load extension in new window
x Load extension in new tab
the user selects one of those, and the background.js script can call the above code to load the page, which will load the html file from your extension codebase that you so desire.

Saving a file from Chrome Extension

I am building a Browser Action type extension for chrome. The end result is that a user clicks the extension button, and starts to download a file from a known domain.
I have seen some similar answers but they all tell you how to generate the file (as I understand), whereas I have the file ready on the server.
I tried adding an A (link) element in the popup html, and having the user right click and "save as", but this option is not available in the extension popup. I have tried navigating the extension popup to the file's URL (location.href), but it shows a page not found error.
How can I just let the user download the file? Preferably when clicking the extension button but a second click inside the extension's html is acceptable solution.
Found the answer in this recent thread: CHROME ext/app - single click for image download
Just using the download manager api (I always thought it was just to access the downloads list).

Calling chrome.browserAction.setIcon from content script the way it is done in background script

I am making an extension for chrome. It fetches data from webpages and emails it via local email client. I have a toolbar button which user has to click to invoke the script.
My script works for a few selected urls. I want my toolbar button to change icon based on whether the url is among our list or not. For example for site1 it should be redicon.png and for site2 it should be blueicon.png. I can change button icon using chrome.browserAction.setIcon. But the problem is that this API does not work in content script. It works fine in the background.js file but not in content.js. Kindly tell me how to achieve this.
I know using pageAction instead would do the trick but my client requirement is that the toolbar icon should change rather than appear and disappear.
What you need to read about is message passing. You are right, content scripts have limited chrome API. However, you can contact background page from content script and tell it to execute anything from chrome API for you. First, you need to create a listener on a background page that will be waiting for messages and then send a message from a content script.

click of a submit button on any website using Google extension

On the click of a submit button on any website eg. Amazon, I want a .html to be triggered using google extension. please let me know if it is possible.
You can indeed execute scripts on (almost) any page using content scripts that can manipulate the DOM, allowing you to add an onsubmit event listener to a form (more reliable than onclick on a button as it is fired however the form is submitted - e.g. hitting ENTER).
What exactly do you mean you "want a .html to be triggered"? Triggered in what way? If you want to open another tab when this happens, you can do this using message passing to tell your background page to do this for you using the chrome.tab.create API method.

Resources