forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Privacy mv3 sample (GoogleChrome#956)
* Implemented mv3 privacy API sample * Added mv3 privacy API sample * Expanded sample and updated readme * Update service-worker.js
- Loading branch information
1 parent
be33406
commit ef7eb4c
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# chrome.privacy | ||
|
||
This sample demonstrates using `chrome.privacy.services` to get and set privacy settings. | ||
|
||
## Overview | ||
|
||
The service worker sets the default value for Autofill using `chrome.privacy.services.autofillEnabled.set()` when the extension is installed. Whenever a page is loaded, or when the action button is clicked, the extension will display the current Autofill setting of `autofillAddressEnabled` by updating the extension badge. | ||
|
||
## Running this extension | ||
|
||
1. Clone this repository. | ||
2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). | ||
3. Pin the extension to the taskbar and either click the action button or load a webpage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Privacy API sample", | ||
"version": "1.0", | ||
"manifest_version": 3, | ||
"background": { | ||
"service_worker": "service-worker.js" | ||
}, | ||
"permissions": ["privacy"], | ||
"action": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
chrome.runtime.onInstalled.addListener(() => { | ||
// Set default value for Autofill Enabled | ||
chrome.privacy.services.autofillEnabled.set({ value: true }); | ||
}); | ||
|
||
chrome.runtime.onStartup.addListener(() => { | ||
updateAutofillEnabledStatus(); | ||
}); | ||
|
||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { | ||
if (changeInfo.status === 'complete' && tab.active) { | ||
updateAutofillEnabledStatus(); | ||
} | ||
}); | ||
|
||
function updateAutofillEnabledStatus() { | ||
chrome.privacy.services.autofillEnabled.get({}, (details) => { | ||
const autofillEnabled = details.value; | ||
const badgeText = autofillEnabled ? 'Enabled' : 'Disabled'; | ||
const badgeColor = autofillEnabled ? '#00FF00' : '#FF0000'; | ||
|
||
chrome.action.setBadgeText({ text: badgeText }); | ||
chrome.action.setBadgeBackgroundColor({ color: badgeColor }); | ||
}); | ||
} | ||
|
||
chrome.action.onClicked.addListener(() => { | ||
updateAutofillEnabledStatus(); | ||
}); |