Background Page Doesn't Show as Active User - google-chrome-extension

I added Google Analytics to a Chrome Extension. It is reporting events correctly as well as recording popup page views. When the extension is reloaded it correctly records a view of background.html which I explicitly call.
Problem: Despite the extension having a persistent background.html page, "Active Users" in the Real-Time section of GA shows 0. I would like to be able to see the # of concurrent users of the extension at a given time. Is there a way to do it?
Possible Solution? - When I open the popup it displays an active user for some number of minutes before dropping back down to zero. Do I need to create a heartbeat function of some kind that pings GA every X minutes to keep a user active. It seems a big "chatty" to do that.
Is there a better solution?

Related

Chrome extension: How to do not lose state of my extension when user changes/reloads the page

I'm currently developing an extension that comes in different parts:
- background script (Chrome background.js
- content script (Chrome content-script.js)
- popup script (popup.js and loaded from the iFrame)
- iframe.html (iframe to be loaded when user activate the extension)
It works great except that I lose all the settings/context (used in the popup script to display info in the iframe) when the user change of page or reload the page in the tab.
Technically I want to isolate the extension per tab (each tab can have its own config) but when a user navigate in a same tab the context should be kept.
Question is: what is the best way to achieve that?
I'm thinking about persisting all the context in the content script and reload it when the event chrome.tabs.onUpdated is fired. Is it the right approach?
I recommend you to read about chrome.storage. You can store data there, both background and content script have access to it.
And probably you will need chrome.runtime.sendMessage and chrome.runtime.onMessage to have conversation between background and content. Each time content script runs in a tab it can request background whether this tab have some existing data or not.

How to prevent Chrome from automatically blocking audio capture

I'm developing an extension that requires audio access. Under normal circumstances, the user will choose either "Block" or "Allow", and that is fine. Both actions will put the extension in the appropriate place in settings/content/microphone. But while testing, I found if the user were to simply close out the Block/Allow popup by clicking on the "x" in the corner:
then I start to get PermissionDeniedErrors from navigator.mediaDevices.getUserMedia (which makes sense). But there are two big problems to this:
Chrome stops prompting the user if they want to block/allow - it just silently blocks it.
The blocked extension DOES NOT show up in settings/content/microphone. So there is no way for the user to unblock it.
Then some time later (hours? days?), the prompt will come back.
I was digging in the Preferences file to see if maybe something about the extension is in there that wasn't getting surfaced to the UI, and I found this:
From this, I am guessing that Chrome is detecting the "dismissals", and just automatically begins blocking the setting for a period of time ("embargo days").
Is there any kind of action: either programmatic or user-based that can be taken to help direct users to unblock the extension?

Can Chrome Extension’s new options_ui trigger a page action?

I’ve been placing a page action on the options page of my Chrome extension. options.js calls chrome.runtime.connect({"name":"someName"}), and background.js has
chrome.runtime.onConnect.addListener(function(port) {
chrome.pageAction.show(port.sender.tab.id);
});
Unfortunately, in the new options_ui with the recommended default (and someday mandatory) "open_in_tab":false, the Sender's tab won't be set. Is there a way to get the tab id in order to show the page action?
I could use tabs.query to get the chrome://extensions/ tab, but that requires the tabs permission, which I currently don’t need. Active tab seems like it would work, but it doesn’t provide the tab id and isn’t enabled by opening an option dialog (source).
(Why do I want the page action on my options page? The extension works with a website that is only available ~7-10 weeks per year. I’d like my users to be able to interact with the extension the rest of the time, so that they can get used to the process. But I don’t want to adjust the displayed extension permissions just to do so. I can accomplish this by having the options page pretend to be the website in question.)

Serverside Xpages application update causes my browser page partial refresh actions stop working - how to detect it?

Any Xpages application update in design causes the application refresh which removes scope variables, session etc. When this occures and there is a page opened in users browser with some partial refresh action buttons ... such buttons simply do nothing when clicked which is quite confusing. No message that's warning the user that the page is stale or something. Is there a way how to detect such situation in general so I can inform user in browser with some dialog that he should reload the entire page?
For all scope variables above request (which gets initialized when you send a request and is always shiny and new) you never can take their existence for granted. Best example: user leaves a form open, locks the PC, goes for lunch, lets the session expire (which also deletes the view scope). (S)he comes back, opens a new tab and logs in - so there is a valid (new) session, hits submit in the first tab -> bum all your code fails.
This is the same scenario as an updated design short of the scenario Panu was pointing to.
So in your code check for the existence of your scoped variables and force a full refresh. Or (I like that better) add an error to the page so that gets displayed with an appropriate action.

Submit a form in the background automatically

I want to create a Google Chrome extension that runs constantly in the background, even when Chrome windows are closed - this is what a Background Page is for, correct? Or should I be looking at something else?
Basically what I wish to do is have a setTimeout() load a page every 5 minutes and if its presented with a login page, automatically logs in with a given username and password, otherwise it does nothing.
This is simply to keep the session alive...
Is this possible to do?

Resources