Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension: show browser action popup only in some cases

I have a chrome extension. When the user clicks the icon I want to:

  1. Check if the user is logged in. This uses google storage (I've got this code already).

  2. If user is logged in, there should NOT be a popup.

  3. If user is not logged in, show browser action pop-up with login post/ajax form.

Google says "If a browser action has a popup, the popup appears when the user clicks the icon." https://developer.chrome.com/extensions/browserAction.html

So I guess not? I could instead add a form to the page DOM, but I'd rather not do that. Any other nice solutions?

like image 457
user984003 Avatar asked Oct 24 '25 04:10

user984003


1 Answers

Use chrome.browserAction.setPopup({ popup: ''}) to remove the popup.

From the browserAction.setPopup docs:

Sets the html document to be opened as a popup when the user clicks on the browser action's icon...

popup ( string ): If set to the empty string (''), no popup is shown.

You can use chrome.browserAction.setPopup to specify a popup page to show, or no popup at all. However, you must specify the popup before the user clicks the browser action; I don't believe you can change it "just in time" as the user clicks. You should simply start with the popup active by default, and then turn it off once the user has successfully logged in.

like image 128
apsillers Avatar answered Oct 27 '25 03:10

apsillers