Browser extension popup navigation? - google-chrome-extension

How are you supposed to handle navigation within an extension popup?
I tried to make a button that when clicked calls a function that sets window.location.href to newpage.html, but it does nothing.
I know there's a browser.browserAction.setPopup function, but going off the description of it that only seems applicable for setting the first page when opening the extension, and not for navigation.

Related

How do you click a button in a browser popup window

I'm new to using Watir and have a problem. Within my browser page there is an option to add a note. This brings up a window within the browser which has the following id:
span id="ui-id-2" class="ui-dialog-title">Add Note</span
I can't work out how to use the controls within this window such as the 'Save' button as Watir doesn't seem to recognise either the window or the controls
So if I wanted to use same type of Save button within the main browser it would be fine; I'd just use browser.button(:id=> "Save").click.
Trying to use it within the popup though won't work as Watir can't recognise it within the popup. Any ideas appreciated!

How to open the default popup from context menu in a chrome extension

I have developed a chrome extension that opens a popup when I click on the icon near the address bar. Everything works fine, however I want to add some functionality to it. So I thought I'd also add a context menu item so that the user can simply search for the highlighted word. I want the popup to showup when the user clicks on the item in the context menu(the default popup in the top right corner and not a new popup window or a new tab).
Can I have this functionality? If yes, how do I implement it?
You can't make the popup page show programmatically as if the user clicked it.
However, you can still have something display based on the background script / content menu click. There are 4 main options for your background script:
Open a new tab to the popup.html page
Programmatic injection of javascript to construct a popup-like dialog on the page
Content script message passing to do the same as above, using a running content-script.
Use the notifications API for a simple minimally stylized message to the user.
Options 2, 3, 4 will allow the user to stay on their tab without any navigation. The notifications API route is the simplest to use if you just want some quick notification to the user, and there are fewer security snags. 2 and 3 require more book-keeping, but you can make the dialog look like your popup.
There should be an API for it now (as in 2023)
https://developer.chrome.com/docs/extensions/reference/action/#method-openPopup
update: tried, but failed, there was a bug.
https://github.com/GoogleChrome/developer.chrome.com/issues/2602
hope they fix it soon.
I was looking for extensions that I have already been used, but forget its name. This extension opened up the result into Context Menu, without open new TAB or popup.
may be useful
https://developer.chrome.com/extensions/contextMenus

chrome extension popup not open immediately

I'm writing a chrome extension.
When i click the browser action button in the first time - all goes well.
When i click the browser action button the second time, after several minutes of not clicking it, it takes more than 10 seconds until the popup is shown.
I've tried commenting out all of the periodic methods in the background and all of the methods in the load event of the popup, but it still doesn't shown immediately.
any suggestions?
I had a similar issue with the popup when I was adding an iframe to the popup. Chrome would wait with showing the popup until that iframe was loaded.
For me the fix was wrapping the code that added the iframe to the HTML in:
setTimeout(function(){
// Code here
},0);
This way Chrome showed the popup first, after which it begin with loading the iframe.
Maybe you have a similar problem?
i have seen this behavior before when you have a long running ajax call that you are doing on popup load.. hard to tell further without code samples or description of what you are doing

Yahoo UI the popup implementation with YAHOO.widget.Dialog

I used the Yahoo.widget.dialog to implement a popup window. Currently, it popups only on the page which is belongs. If I am working on the other (tab browser) pages. The popup window will be not seen.Could somebody supply some help for this ?Thanks
You could either switch to window.alert() or use window.open() to open a new pop-up window containing your content.
Neither one is something I'd personally want to experience, but those are your two options for opening a pop-up outside the page. Window.open will get caught by many pop-up blockers so you'll need to watch for that.

How is "Are you sure you want to navigate away from this page? " generated in browsers?

I have a page where I open a "modal window". It is really just a DIV, with an IFRAME inside, where I load another page. When I want to refresh the page, the browser pops up a window saying "Are you sure you want to navigate away from this page? Reloading this page will cause the modal window to disappear. Press OK to continue, or Cancel to stay on the current page."
How does this message get generated? How does the browser figure out that I have a modal window there, because I don't use any window.open() call from JavaScript? Is there any way to disable this behavior of the browser.
It may be body.onunload in the source of the page loaded in the IFRAME.
As the modal window is essentially an IFRAME, then when you close (or refresh) the main window, the browser knows it is killing that IFRAME, hence any body.onunload in that IFRAME fires.
If you have a function that handel onbeforeunload, automaticaly the Firefox message is generated.
you can disable it by returning null at the and of your handler.
This could be caused by some script modifying all off-site links to display this modal window, and then return true, or return false based upon your interaction with the modal window.
If you want to strip that behavior, you could remove all click events for external links.

Resources