Chrome Extension: close background page after closing Chrome - google-chrome

I have an extension with a background page, and by default this causes Chrome to persist after you close all windows, and puts the Chrome icon in the system-tray. I would like to avoid this -- I do not want my extension to cause the Chrome process to persist after closing all Chrome windows, nor do I want to cause Chrome to appear in the systray.
According to the only docs I could find on this indicates that the user can set this option globally across all extensions, but that isn't what I'm trying to do. I'd like the extension to be unassuming / unobtrusive, and don't want to change the user's browser behavior. Does anyone know how to accomplish this while retaining the ability to have a background page?

UPDATE
With manifest version 2 you can now run event pages that are not persistent. Event pages are very similar to background pages but are only loaded when needed by the extension.
Example from the event pages doc on setting a non persistent event script in your manifest:
{
"name": "My extension",
...
"background": {
"scripts": ["eventPage.js"],
"persistent": false
},
...
}
Here is a tutorial on migrating your Chrome extension to manifest version 2.
OLD ANSWER
Currently, if your extension has a background defined in the manifest.json file, it will run before Chrome is launched and continue after all windows of Chrome are closed. That is unless the user changes their settings like you mentioned. There may be future versions of Google Chrome that allow for different functionality but you, the developer, won't be able to get around this issue at this time.
An excerpt from the background manifest docs
Makes Chrome start up early and and shut down late, so that apps and extensions can have a longer life.
When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.

Related

How to prevent a chrome extension from forcing a tab switch event?

I am experiencing some strange behavior from a Chrome extension that I am developing. The extension is a fork of the Mozilla PDF.JS chrome extension, which provides a custom PDF reader that overrides the default Chrome one.
The problem is that when I have a PDF file open using the extension in an inactive tab and I have a different tab activated, sometimes the inactive PDF tab will suddenly reload and forcibly switch the browser's active tab back to the PDF. I have noticed that it happens most often when my computer is running low on available memory.
For example: Tab A is displaying https://www.example.com/test.pdf via the extension, and Tab B is displaying https://www.example.com/home.html like any regular chrome tab. The user is actively using Tab B when suddenly Tab A reloads and changes the current tab to Tab A.
This is very poor design. I do not want my extension suddenly changing the user's current tab without their consent. Any ideas of how to approach this problem? I haven't been able to find any resources online about this. So far I have made only minimal changes to the extension. The main difference so far is that I updated the manifest.json (see below) from V2 to V3. Outside of that I haven't changed much. I don't mind if the extension reloads itself when resources are low, but it can't be changing the user's current tab against their will.
manifest.json
{
"manifest_version": 3,
"name": "PDF Viewer",
"version": "2.16.0",
"description": "Uses HTML5 to display PDF files directly in the browser.",
"icons": {
"128": "icon128.png",
"48": "icon48.png",
"16": "icon16.png"
},
...

Changes to PWA manifest not applying

I'm having trouble applying updates made to Progressive Web App manifest. Updating stuff works otherwise just fine, but if I change something from my manifest, like background_color, the launch screen color will not change. I have monitored my server to see that manifest.json is indeed fetched. Restarting phone doesn't apply the changes either, the only way seems to be to uninstall the PWA and add back to home screen.
On desktop, chrome developer tools show that the manifest is correctly fetched and the changes can be seen in the dev tools. Is this expected behavior? Is there a way to make changes to manifest apply after the PWA has already been installed?
This has been addressed in the official The Web App Manifest docs:
Note: If you update your manifest.json file in the future, those
changes won't be automatically picked up by the users unless they
re-add your app to their home screen.
So, this is indeed the expected behavior.

Why is my Chrome Extension grayed out?

Problem
A chrome extension I wrote is grayed out, and I can't figure out why.
Context
I wrote and submitted a Chrome Extension called Pull Favors to the Chrome webstore.
It uses the CSS order property to sort and group GitHub Pull-Requests in a logical way.
The other day I noticed that several of my extensions were grayed out, and 'blocked'--meaning they no longer work. One of these was Pull Favors.
According to this support article:
If you see a message saying "Extensions Disabled," it's because Chrome has turned off one or more of your extensions to keep your data safe while you're browsing the Internet. The extensions that Chrome turned off either didn't come from the Chrome Web Store or were installed without your permission."
My extension is published in the Chrome webstore and was certainly installed with my permission.
I've tried uninstalling and reinstalling to no avail.
I suspect there's something wrong with my extension (since a few other extensions seem to still work), but I can't figure out what it is or find anything about it on the internet.
What's going on?
Research
Chrome seems to have implemented a new policy in November 2013, which has caused some uproar in the community, which prevents Windows users from installing extensions from outside the web store.
I'm not sure why this is affecting me, as I'm an OS X user and, as I said, my extension is distributed through the webstore.
Add browser_action.default_icon in your manifest.json file
{
...
"browser_action": {
"default_icon": "icons/icon-32.png"
},
...
}
Before
After
In one of the last couple updates, they did something weird with the extensions that now makes all enabled extensions show up in either the toolbar or in the menu. In your case, the extension icon is grayed out because you don't even use a browser action or a page action, so it is just showing the icon. So it isn't disabled, just doesn't have an active state so is grayed out.
A quick search doesn't seem to turn up a blog post about it, but if you right click on the icon you can hide it in the menu.

How do you test/debug a Chrome extension's event/background page?

I have an extension that has the following files:
content.js, background.js, manifest.json, mystyles.css, jquery-2.0.3.js and icon.png.
I can set breakpoints in the content.js file via the Chrome Debug Tool via the "Sources" tab and via the "Content Scripts" tab. My problem is that I can't find a reference to the "background.js" file, so I can set a breakpoint in it. Can someone tell me what I am overlooking or doing wrong?
References:
I have watched the Chrome Debug Video on YouTube.
I have read the Chrome Tutorial on Debugging.
If you open up a new tab and go to chrome://extensions, you will see a list of installed plugins, including your own. Next to your plugin, there will be a link to "Inspect Views" pointing to a background.html page or a generated one in your case. This will launch a new debug window in Chrome that will allow you to browse to your background.js file and set breakpoints (by clicking on the line number)!

How to disable cache on chrome for Android?

How to disable cache on chrome for Android?
I change my page content, and refresh the page, but the content still is old.
I have set the nginx config like below, but it has no effect.
#disable cache
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma no-cache;
add_header Expires 0;
Is there a way to get my newest page without manually clear cache again and again?
This may not be the easiest way, but it will 100% work and should be part of your development setup anyway.
Using Google Chromes web tools on Windows or Mac will allow you to do "remote debugging".
Enable remote debugging on Android device through Developer Menu in settings.
Connect phone to PC using USB
Open Google Chrome and access the developer console (F12)
Click on the three dots (top right) > more tools > Remote devices.
Scroll down to select your mobile device, at this stage you should see all chrome instances open on your phone. Select the instance you wish to "force reload and disable cache" by pressing Inspect
Another screen should appear allowing you to access the network tab and select "Disable Cache"
Currently there is no way to disable cache on chrome for Android but it is possible to clear the cache.
UPDATE: As of now there is a way to disable cache with requires your phone to be connected and needs remote debugging, please refer to Dean Meehan's answer for more info
Follow these steps to clear the cache.
http://www.refreshyourcache.com/en/chrome-android/
Click on the menu button (three dots in the topright corner).
Click on Settings in the menu.
Click on Privacy in the menu.
Click on Clear browsing data... at the bottom.
Select Empty the cache from the list.
Confirm clear browsing data.
I know the question is asking about disabling cache on chrome for Android, but this may help people looking for a solution to mobile development.
To see changes on your website with your Android device use the New incognito tab in chrome web menu.
Click top right drop down menu in chrome browser
Click "New incognito tab"
Navigate to your website and see all your most recent changes.
IMPORTANT: To see new changes after viewing with incognito, you must close the incognito mode completely and reopen due to the current tab also caching.
To disable the cache first you'll have to disable scripts / css caching on the ones you are editing.
In order to do that, add a timestamp to your file inclusions :
<link rel='stylesheet' href='/static/css/main.css?t={{ts}}'/>
<script type='text/javascript' src='/static/scripts/main.js?t={{ts}}'></script>
{{ts}} being a timestamp (I'm using jinja templating).
Then if you edit your html page, you could change the request adding a random parameter to it as such :
test 1 :
mywebsite.com/this_page
test 2 :
mywebsite.com/this_page/?i=1
test 3 :
mywebsite.com/this_page/?i=2
...
It's more a hack than a real solution, but chrome kindly ignores the cache-control meta, so there aren't lots of clean way to do it.
The following bash script will rename
<script src="path/to/app.js"></script>
to
<script src="path/to/app.js?t=18:15:45></script>
in an index.html file, which will prevent mobile caching.
#!/bin/bash
time=$(date +"%T")
sed -i "s/app.js/app.js?t=${time}/" ./path/to/index.html
Download this app : App Cache Cleaner
Open the app
Go to the app settings via the '3 dotted' button
screenshot
Tick mark the option to show widgets and the rest is upto you
You may as well disable Chrome's Data Compression policy and preloading of pages.
As of now, there are no 'disable cache' option in chrome
screenshot2
PS:i cud not show pictures because of my low rep, help me increase that too ;p