I am trying to create a Chrome extension with the following specs:
- Install extension. --> Click on the extension icon.
- Every time the icon is clicked, a background script checks if access token exists.
- If access token doesn't exist (which is the case for the first time user), a separate window will display (using window.open()) prompting the user to login.
- If access token exists, a chrome extension popup should show up once the icon is clicked.
In my current implementation, I am not setting a default popup in manifest.json. If the background script finds an access token to exist, it sets the popup using chrome.browserAction.setPopup. But, the popup shows up only after I click the icon twice. I know this is because it sets the popup on the first click, and then displays it on the second. But, is there any way to get it to display on the first?
Is there a better way of implementing this logic so I don't have to keep setting the popup every time access token is detected and requiring the user to click twice (this is not very user-friendly in my opinion)?
Thanks!
I am trying to create a Chrome extension with the following specs:
- Install extension. --> Click on the extension icon.
- Every time the icon is clicked, a background script checks if access token exists.
- If access token doesn't exist (which is the case for the first time user), a separate window will display (using window.open()) prompting the user to login.
- If access token exists, a chrome extension popup should show up once the icon is clicked.
In my current implementation, I am not setting a default popup in manifest.json. If the background script finds an access token to exist, it sets the popup using chrome.browserAction.setPopup. But, the popup shows up only after I click the icon twice. I know this is because it sets the popup on the first click, and then displays it on the second. But, is there any way to get it to display on the first?
Is there a better way of implementing this logic so I don't have to keep setting the popup every time access token is detected and requiring the user to click twice (this is not very user-friendly in my opinion)?
Thanks!
Share Improve this question asked Jul 3, 2015 at 17:04 llams48llams48 4072 gold badges8 silver badges17 bronze badges2 Answers
Reset to default 5So after serious Hardwork of one day. I figured out a way to do this. So the only way potentially doing this is to set your accessToken in a cookie to your domain and let chrome extension track cookies of that domain. There is an event in chrome.cookies.onChanged
- this lets you track any cookie that has been changed.
So the steps are as follows
- Set your default popup to login/singup screen
"browser_action":{"default_popup": "signin.html"},
- In your background.js, you have a function to track your cookie - and update your screen based on that
- Also check if user has already logged in on intial run of the background script
check my gist for more understnaing - background.js
Sadly, as you describe - not yet.
There are talks about enabling you to open a popup programmatically in certain circumstances (yours included), but they got very plicated and so no timeline for that.
However, in your case it's a relatively simple fix..
You should call setPopup
as soon as you get your token, so that the next click succeeds.
If you need to verify that the token is valid, it's best to do that after the popup opens. If it's invalid, show a big "log in" button in the popup instead of its usual contents.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745162917a4614477.html
评论列表(0条)