How to prevent Chrome from automatically blocking audio capture - google-chrome-extension

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?

Related

Chrome Extension Disappears while clicking outside of its resolution

Is there anyway that I can make Chrome Extension's window stick in window even while clicking outside of its resolution?
I'm trying to make it Sticky on the window for one simple google login so that I don't need to go back again to click extension to open it.
By using tabs API you could retrieve windowId of the window you want to focus on. You could do it only if needed e.g. by using query method from that API. You could pass url for example.
If you created a window that you want to be still focused then you have its id already in the hand.
After that, you could use window API update method in order to draw attention or focus. Take a look at updateInfo params - focus and drawAttention.
The same could be done by using tabs API. You could pass tabId and the URL you want to redirect someone.
Now in order to make it work you have a couple of options:
You can use setInterval which would be used to check if the tabId and windowId you want are active and focus the window/tab you want in another case.
Because in the MV3 extensions using setInterval is not recommended you could use alarms. Please take a look at AlarmCreateInfo, when param should help you instead of triggering the alarm periodically.
You could also use event listeners from both windows and tabs API to listen on tab / window focus change. Then you will be able block the change (from user perspective) by methods I described before.
You should play with all approaches and pick on that suits you, because all of them have some drawback. But don't want to make that comment very long.

Background Page Doesn't Show as Active User

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?

Can I re-open my popup after user grants permisisons?

I'm testing edge cases for my chrome extension; handling cases where the user has not yet granted the permissions I need.
My popup calls chrome.identity.getAuthToken and, as expected, the user is show the chrome permissions screen and asked to approve.
But, as a side-effect, this closes my popup. I'd like to either keep the popup open, or re-open it after permission has been granted. Is this possible?
'Popup' is ambiguous.
A page action can be triggered dynamically using chrome.pageAction.show(integer tabId).
A browser action cannot.
I don't know about chrome.identity.getAuthToken but e. g. chrome.permissions.request does not close a page action.
I don't think there is a way to stop it closing either. E. g. a beforeUnload event listener does not seem to work.

How to detect when another Chrome Extension overrides the same page

An example would be if my extension overrides the newtab page and the user installs another extension that also overrides the newtab page. Currently, only one newtab extension shows up and it usually isn't mine.
What can I do to detect when such a conflict occurs and inform the user of such?
The management API doesn't tell me if the extensions override any pages, so I sadly can't use that.
This doesn't seem to be an exant feature of the API. I'd suggest you open a bug at http://crbug.com.
Failing that, you can perform the following nasty hack (which I haven't tested):
Have your new tab page send a message to your background page whenever it loads.
Listen for chrome.webNavigation.onBeforeNavigate events that deal with chrome://newtab:
chrome.webNavigation.onBeforeNavigate.addListener(function(details) {
/* send message */
}, { url: [{ urlEquals: 'chrome://newtab/' }] });
When webNavigation sees the browser load chrome://newtab but you don't see a message to your background page shortly afterwards, your new tab page is probably not being used. From there, you can send a notification, or open another tab/window with a notice.
Unfortunately, this requires the webNavigation permission, which is unfortunate if your extension doesn't otherwise need it. The warning that it carries ("This extension can access your tabs and browsing activity") might scare away some potential users, especially if there's no reason for it that is obvious to the user. (Then again, perhaps I'm being too optimistic about the security-conscientiousness of users.) If your extension currently uses the tabs API, then it already carries this notice anyway.

tabs permission or content script?

I'm writing an extension that needs to show a page action on amazon.com pages.
Would it be better to request the "tabs" permission or to inject a content script into amazon.com pages?
The tabs permission strikes me as using less resources (because it just checks the URL against a regex in the background script) but I think it's a scarier permission message ("access your tabs and browsing activity")?
Injecting a content script into amazon.com pages seems like it would take more resources it but would only need permission to amazon.com...
It is a generic question and answer depends on Client to Client. You have pointed out the + and - of each.
I suggest you to go for content scripts if your clients are particular about security and privacy, in this you are adding an extra load to pages(with content scripts and message passing) which may slow down the normal execution process.
I suggest you to go for tab permission, if you are all about performance. It is a native API, and executes in background page no extra load on tabs. Many extensions on web store does use tabs API, i dont think this would scare them as this is not new.
However, it is all about your target section of users.

Resources