Chrome Extension, trigger click on the icon - google-chrome-extension

I searched on Google and StackOverflow, and I was not able to find a solution to my problem (to my greatest surprise).
I'm looking to display the popup, exactly like when the user click on the icon of my extension, but via javascript.
The idea behind it is simple : On a specific page, I inject a button and add an event listener on it ("click"). When the user click on that button, I'd like to display the tooltip, simple as that :)
... but I can not find anything related to it. Any idea ?
Thank you in advance.

Opening the popup is impossible without user interaction. For good reason too, remember that no one likes popups that open themselves. What you can do is inject your popup onto the site the user is at, through a content script.
https://developer.chrome.com/extensions/content_scripts

As per your description,
On a specific page, I inject a button and add an event listener on it ("click"). When the user click on that button, I'd like to display the tooltip, simple as that :)
I think what you need is just chrome.pageAction, it's similar to browserAction, while represents actions that can be taken on the current page, but aren't applicable to all pages.

Related

How to follow a link that is actually a click button

I need to fill a form aproximately 100 times a day. I tried with selenium but it is quite slow because it is using a web browser. It's working quite well with mechanicalsoup until I need to click "Accept" button. Clicking it activates other tables that need to be filled but are inactive before clicking this button. I tried to point to the button and then br.follow_link(button) unsuccesfully. I attach the piece of HTML that I need to fake. I'm looking for a way to produce the effect of clicking avoiding using Selenium.
Aceptar
Sounds like you need JavaScript capability so the button's click would render the tables, but MechanicalSoup doesn't do Javascript.
MechanicalSoup's docs says:
MechanicalSoup automatically stores and sends cookies, follows redirects, and can follow links and submit forms. It doesn’t do Javascript.

Run a javascript function on click of popup icon of chrome extension

As chrome.browserAction.onClicked works only if there is no popup, is there any alternative method to fire a query when browser action icon is clicked?
Let me make myself clear..
I have more than one view i.e, html files in my extension. My default popup in index.html
Whenever I click on the icon I want to fetch some data from server. If I include this function in index.html or index.js, this function gets called every time I go to that page. Can anyone help me?
Thank you in advance.
What I would do is:
Have the behavior take place in the onload handler of the page. Since it sounds like the default popup page, index.html, can be loaded as time when the user is not creating the initial popup, I would create a page that is a dedicated initial popup load page that is not used anywhere else. This page could redirect to index.html or include it as an iframe.
Another option is to have index.html take a query string indicating how it is being used. Your initial popup could be index.html?init=1 and all other inclusions of the page simply use index.html. Then use window.location.search.substring(1) to test if a query string is present and take the appropriate action.
I'm also looking for an solution to this and I'm wondering if it is possible to start the browser action with no popup, detect the click, then set a popup with "setPopup()". If it works it doesn't seem like the nicest approach, I hope someone knows of a better solution.

Extension-Specific Context Menu

I'm trying to add an item to the right-click menu on my extension. I've tried to find a method which would work, but a lot of the results seem to deal with context menus on the actual page, not the extension icon itself. The contextMenus API doesn't seem to work for this, unfortunately.
There is currently no API for that. Head for Chromium Issue 78631 and click the star to cast your vote for it and receive updates by e-mail. In the meantime, you could create a popup with a menu that lists both the primary action and the actions you would have put in the context menu.
(I assume you're trying to add the context menu item to your browser action. Your question is a little ambiguous.)

Can Popup page use DOM elements created in Background Page

Actually, I want to store some data in background page and the popup page just show that part of data say Data as a div element created in background page document.createElement("div"). Here, the background page will register some listeners to the tab update and change the Data elements accordingly. What the popup will do is to get that Data and appendit use the document.appendChild(Data).
(The purpose I intend is this will cause the popup changes immediately while the tab updage is triggered.)
However, the elements are shown as usual, what I am facing very headache is I have registered the onclick for the div object in backgroundpage as onclick="chrome.extension.getBackgroundPage().somefunc()". However, the first time, all the click will triger the right behavior but after the popup loses foucs and get focus again, all the click won't work.
I try to put something like change the onclick="somefunc()" and leave the func within the script of popup page. And there I want to log whether it is called by console.log("clicked"). Here, something unbelievable happens, the function is succefully trigerred BUT the console is null here, I cannot even call chrome.extension.getBackgroundPage() as well.
Here are a list of questions, maybe very hard to express for me...
1. Whether I can reuse the DOM element from the background page to the popup page directly by appendChild(chrome.extension.getBackgroundPage().getElementById()?
2.Will the onclick event registered in the background page still work in the popup pages?
3. What's the problem with the problem I am encountering? I have tried many ways to find out the reason but all in vain at last...
Best Regards,
If you need any more information, please let me know.
(PS: I am wonderning if it is called something like the event propogation, however, I am not an expert in this two pages communicating...)

browser causing multiple button clicks

I have linkbutton that has the onclick event handler. The control is disabled as soon the user clicks but certain users are able to click multiple times.
Not able to reproduce. Could it depend on the browser?
Please help with any ideas
I'm sorry for commenting on this by way of answer field, but I have no other way to do so.
You will need to be a little more specific about the case; could you include the code fragment where the bug seems to occur?

Resources