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.
Related
I have a website which runs a service-worker. When I install the website as a PWA App using Add to Homescreen (standalone mode), the site works fine, except that any target="_blank" links cause a duplicate request on the server side - there are two simultanous requests, but only one window opens. This happens even when service worker has no caching logic (fetch handler is empty)
I'm seeing this on Chrome (Huawei, Android 9), as well as Chrome (Samsung, Android 6) and Samsung Internet Browser - but not on iOS Safari.
The duplicate request happens no matter if there is any fetch event implemented in PWA or not
Only one debugger event gets caught in service-worker fetch event, fiddler sees two requests
Only happens in "installed" PWA, not in regular browser or non-PWA homescreen website shortcut
The resource is not cached (or supposed to be cached)
I've made a minimal repro application that I can replicate the issue in:
/index.html
/page.html
/service-worker.js
/manifest.json
index.html:
<head><link rel="manifest" href="/manifest.json"></head>
<body>
CLICK ME
<script>navigator.serviceWorker.register('/service-worker.js', { scope: '/' });</script>
</body>
manifest.json:
{
"background_color": "#FFFFFF",
"description": "Repro application",
"display": "standalone",
"name": "Repro application",
"short_name": "Repro application",
"start_url": "/index.html",
"theme_color": "#FFFFFF"
}
service-worker.js:
(function () {
'use strict';
self.addEventListener('fetch', function (event) { });
self.addEventListener('activate', function (event) { });
}());
Also happens without fetch event at all, or with fetch event just returning a network fetch promise (so default browser behaviour)
page.html content doesn't matter (if it's not there, it just 404's twice)
Only the target="_blank" links hit the server twice, "_self" works fine. Any ideas how to track down what's causing the extra hit?
I want to restrict some urls in a chrome packaged app, but when I try to use chrome.webRequest.onBeforeRequest.addListener in background.js in order to detect the call, I get error upon installing the app, 'webRequest' is only allowed for extensions and legacy packaged apps, but this is a packaged app."
My manifest is as below
...
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js", "js/chromeUtility.js","js/customchromeserver/wsc-chrome.js"],
"persistent": false
}
},
"permissions": [
"webRequest",
"webRequestBlocking",
"*://www.xyz.com/*", // want to block this url
"identity",
"storage",
"webview",
...
How do I restrict a url in my chrome app , any suggestions ? Thanks
I could finaly do it since the url I want to block is loaded via webview, therefore I have checked it by using webview event listener for new window something like - webview.addEventListener('newwindow'), )
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;
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.
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/"
]