chrome extensions block from specific domain - google-chrome

Is it possible to disallow chrome extensions from a specific domain.
For example I want extensions that I install run on on other domain, but on the domain test.com I want no extensions at all.
I tried tools->extensions but there I can just disallow from incognito and some part of extensions everywhere.
Is it actually possible?

This is not possible. You have to either use incognito mode or create a separate user (chrome menu->Settings->Users) which doesn't have any extensions.

There's an Extension Automation that handles that for you:
https://chrome.google.com/webstore/detail/extension-automation/ghopjgdkodchjclkkfdekhjfomdbakkb
Automatically enables and disables extensions for specified sites. For simpler browsing and better performance.

The following code disable extensions for http://www.google.co.in/ and enables for other domains, you can customize it as needed; How ever it works only for extensions you create and at all installed instances
manifest.json
{
"name":"Browser Action Demo",
"description":"This Demonstrates Demo of Browser Action",
"browser_action":{
"default_icon":"screen.png",
"default_title":"Browser Action Demo"
},
"background":{
"scripts":["background.js"]
},
"manifest_version":2,
"version":"1"
}
background.js
function browseraction(){
chrome.tabs.query({"url":"http://www.google.co.in/"},function (tabs){
for(i=0;i<tabs.length;i++){
chrome.browserAction.disable(tabs[i].id);
}
});
}
window.onload=browseraction;

Related

Clear cookies ondisabled event for chrome extension

I have this code in my chrome extension! but I would like to clear cookies on Disabled event! .Whenever an extension is disabled or uninstalled it will clear all the cookies.
In manifest.json:
"scripts": ["background.js"]
},
"permissions": [
"cookies",
"https://*/",
"http://*/"
]
In background.js:
chrome.cookies.getAll({domain: ".mydomain.com"}, function(cookies) {
for(var i=0; i<cookies.length;i++) {
console.log(cookies[i]);
chrome.cookies.remove({url: "https://" + cookies[i].domain + cookies[i].path, name: cookies[i].name});
}
});
You don't get any event when your extension is disabled or uninstalled.
You could make cookies relatively short-lived or session cookies - that way they won't persist far beyond your extension's install - but by design you can't react to users disabling your extension.
If you control the domain for which cookies are being set, then you can use chrome.runtime.setUninstallURL to force Chrome to open a page that clears the cookies - this will cover the uninstall part, but not the disable part. There's nothing you can do for disable to clear immediately.

Why is my 'add to home screen' Web App Install Banner not showing up in my web app

I've created a service-worker and manifest.json file in order to display an 'add to home screen' Web App Install Banner for Chrome Browser Users.
It is not working as intended.
Here is my manifest.json file
{
"name": "MySite",
"short_name": "Mysite",
"start_url": "./?utm_source=homescreen",
"icons": [{
"src": "assets/cacheable/images/shortcut/120x120.png",
"sizes": "128x128",
"type": "image/png"
}, {
"src": "assets/cacheable/images/shortcut/142x142.png",
"sizes": "142x142",
"type": "image/png"
}, {
"src": "assets/cacheable/images/shortcut/192x192.png",
"sizes": "192x192",
"type": "image/png"
}, {
"src": "assets/cacheable/images/shortcut/192x192.png",
"sizes": "384x384",
"type": "image/png"
}],
"orientation": "portrait" ,
"background_color": "#fff",
"display": "standalone",
"theme_color": "#fff"
}
Please let me know if I forgot to add anything?
First, let's check if your manifest fulfills the requirements for showing Web App Install Banners.
Requirements
Full (current) requirements for showing Web App Install Banners are*:
Have a web app manifest file with:
a short_name
a name (used in the
banner prompt)
a 144x144 png icon
a start_url that loads
Is served over HTTPS (a requirement for using service worker).
Is visited at least twice, with at least five minutes between visits.
Reference
Okay, so for now let's assume this is all valid. Let's move on to testing.
Testing
To test if you've installed it correctly, you can try the following steps:
Open Chrome DevTools,
Go to the Application panel
Go to the Manifest tab
Click Add to homescreen.
A prompt should now show on top of your browser asking if you want to add the url to your things (on Chrome desktop).
Troubleshooting
If after testing you are getting the following error in your console:
No matching service worker detected. You may need to reload the page, or check that the service worker for the current page also controls the start URL from the manifest
Then please make sure that 1. Your service worker is functioning properly and without errors, and 2. Your start_url matches an actual url of your website that loads. Else, you will never get the prompt to show!
Additionally,
Do note that users (and you!) can also add to the home screen manually through the the (Android) Chrome menu. It is not required to wait for the prompt! I add a lot of websites I tend to use daily to my homescreen, and I hardly ever see a banner!
* Do note that these requirements could change from time to time (they have before!). An update to 'Add to home screen' coming in 2017 has already been announced here
** Also note that these requirements differ significantly from native app install prompts.**
your manifest.json seems good enough.
and the above mentioned points by #Extricate are correct and perfect.
So the next question is have you implemented service-worker for your app?
I read somewhere that an empty service-worker file would work but when I tried an empty implementation of service-worker, it said that
'Site cannot be installed: the page does not work offline'
So I suppose that latest chrome version would not be supporting the A2HS prompt for APP INSTALL BANNERS if you service-worker dont support offline working.
You can try going to Basic web app prompt , go to devtools in chrome, navigate to Application tab.
There you will find manifest.json. On LHS of the manifest file, you can see the ADD TO HOME SCREEN. When you click, it will print
'Site cannot be installed: the page does not work offline'
PFA screenshot for same
In your service worker js file add this one line of code:
self.addEventListener('fetch', function(event) {});
May be usefull, as had similar issue. The Install infobar appeared once and never again.
From Developers Google
The mini-infobar will appear when the site meets the criteria, and
once dismissed by the user, it will not appear again until a
sufficient amount of time has passed (currently 3 months).

Kiosk mode in Node-webkit not working?

I'm trying out the basic tutorial for Node-webkit.
The manifest includes options to make your app go fullscreen or even in kiosk mode, which is exactly what I need.
Sadly, the app does not open in fullscreen or kiosk mode no matter what I put in the manifest file.
I'm on Mac OS, I downloaded "node-webkit.app". I am compressing my manifest.json and index.html into a "app.nw" zipfile, and then opening that with the mac app. Is there anything I'm overlooking?
My manifest file:
{
"name": "mydemo",
"main": "index.html",
"window": {
"title": "baby's first node-webkit demo",
"resizable":"false",
"show_in_taskbar":"true",
"fullscreen":"true",
"kiosk":"true"
}
}
OK, so I'm answering my own question here... don't use:
"kiosk":"true"
Instead use
"kiosk":true
I was under the impression JSON always uses quotes around properties...

Chrome Extension: close background page after closing 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.

How to disable same origin policy in Chrome extension?

Maybe are there some settings to disable this in extension context. Since I'm developing an extension it should be my own responsibility to not shoot my own goal. It is very frustrating to fiddle with this security thing that is totally out of reason when developing browser extensions.
I don't want to make whole browser insecure by disabling it globally. just for the scripts that are set in "content_scripts" section in manifest.json
Your manifest.json file should have the domain you're looking to use in the permissions:
"permissions": [
"http://*.domain.com/"
]