Exit Chrome Extension w/ Background Permissions on Browser Close - javascript

I am building a Google Chrome extension that requires background permissions in order to be able to stream music with the extension closed. I run a script in the background that creates an audio element and plays music, and the [foreground] extension can play/pause. However, when the user exits the browser, the controls go with it! Because of the very nature of background permissions, the extension keeps running and streaming music. But the user can no longer stop it without reopening Chrome.
Please tell me there's a way around this? I want my extension to play music when the extension is not in the foreground, but I also want to quit/stop when the user exists the main Chrome window. To be clear, this is not a background "page" running, it's a javascript file.
Thank you!

You don't need the background permission to have a background script. You can simply remove the background permission from your manifest.

Related

Google Chrome Extension, closing Persistent background page

I have a chrome extension which has a persistent background page in order to stream audio even when the user closes chrome. What I would like is to implement an option for the user to disable audio streaming after chrome has been closed. Right now I am detecting when all chrome windows have been closed and pausing audio, however chrome remains 'open' in the task manager and system tray (note that running in background chrome setting is enabled). This stops audio playback but the chrome process remains open in task manger and the icon remains in the system tray. By contrast if I completely disable the extension and then close chrome, the application closes completely and no system tray icon remains.
This Question suggests that only a user can explicitly close chrome if there is a persistent background page, My goal isn't to close chrome explicitly but simply prevent MY extension from being the one keeping chrome open (depending on user specified options), therefore an event page doesn't seem to be a good fit.
Is there a function call or some other programmatic way I can close my persistent background page once all windows have been closed, if that option has been enabled? Or am I stuck with the chrome application staying open because the background page is persistent?
I've found an answer to my own question so I'll post it here. In order to have a background page you do not need the "Background" permission declared in your manifest. This permission is what allows the extension to stay open after chrome has closed (and potentially open before chrome?) rather than being necessary to have a background page. So a persistent background page will close with chrome if this permission is not set, and will stay open even after chrome is closed if it is set.
Bearing this in mind, the solution for me was to set the "background" permission to optional, and enable it if I wanted my extension to stay open after close, then remove the permission if I didn't want it staying open after close (the user now has an option to toggle this).

Enable chrome extension when a tab is opened matching a url

I am pretty new to Chrome extensions and Javascript so any help will be great. Currently I have an extension that takes the currently playing song on tunein.com and populates links to search for the song on Spotify, YouTube, Google Play Music and Google. GitHub link here for reference. I'm currently enabling the extension when you are actively on the tab where tunein.com is playing but I would like to be able to make it work even when that tab is in the background.
I also worry if this will break my current implementation where I am traversing the DOM to get the name of the song and artwork. A lot of the tutorials I was using to develop this have mainly focused on the activeTab. From my cursory research I would set a flag in localStorage and do a check when a new tab is opened but I'm not sure how to access the DOM of a tab in the background or if that is even possible.
Any help would be greatly appreciated!

How to mute the current tab or block sound for a web site?

I'm looking for a way to mute sound or block it from unauthorized sources,
The problem is that Google Ads is randomly playing videos in ads (very annoying)
For example, I want users to be able to play videos on my web site (I can add a special ID to these allowed elements or data-allowed-element).
I'm wonder if I can hookup to a browser sound event or detect when sound is playing - JavaScript?
Any ideas?
No there is currently no way to detect this browser independent! - There is no event or something else.
Furthermore i dont know exactly how the Google Ads works. I think they are running in an iframe or something which make it harder to detect/mute it.
But may it runns within an audio or video tag, so you can may mute it using the following post. But be careful - You have to mute the video and audio tags within the Google Ads iframe and not within your main window, because then you will have no effect.
https://stackoverflow.com/a/14045788/4275911

How to load https:// websites on click of chrome extension

I have made a Chrome Extension for webpage translation but when I load a https:// based website and click on the chrome extension, it shows the shield icon and asks to click on to load unsafe script. But what I want is, when I click on chrome extension it should automatically load that page and start the translating process, I don't want that shield message to intervene between clicking on chrome extension and my servlet code. I have read about a command --allow-running-insecure-content and I don't know how to use it in my java code to automatically load that website.
I have not done it yet because I am not sure that this is write solution or not and it is also related to security so I didn't want to take risk with my computer without any proper guidance about it. Kindly help me. How to automatically load the scripts without clicking on that shield button.
Thanks in advance.
try to remove the http: or https: and use just //
http://path.to.image => //path.to.image

How to reset location warnings in ios from javascript

Is it possible to reset the location warnings in ios from javascript run on the website?
I am finding that if users keep denying access to their location when visiting my website that eventually they no longer get the choice. Now I know that they can reset their settings on their iPhones but I would like to be able to force the "Deny or Allow" dialog box to appear every time they visit my website.
Is this possible? If so how?

Categories

Resources