Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active June 7, 2019 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primaryobjects/a67c6feec54ef379ac0b4ab4799b3e82 to your computer and use it in GitHub Desktop.
Save primaryobjects/a67c6feec54ef379ac0b4ab4799b3e82 to your computer and use it in GitHub Desktop.
Chrome Extension example to trigger the permission update warning.

Chrome Extension Permissions Update Warnings

The following steps demonstrate triggering a Chrome extension permissions update warning and subsequent disabling of an extension due to new permissions.

This example walks through a simple Chrome extension to make a web page background red. It also includes a content script that displays an alert when clicking the web page.

3 versions of the manifest.json exist:

  • Version 2.0: Declares the initial extension permissions.
  • Version 2.1: Declares new extension permissions and will not trigger an update warning from Chrome.
  • Version 2.2: Declares a new extension permission that will trigger an update warning from Chrome.

Running the Tests

The following steps test the 3 scenarios.

Initial Install

  1. Open Chrome->Manage Extensions.

  2. Click Pack Extension.

  3. Select the source folder and click Pack extension.

  4. Drag and drop the .crx file into the Chrome extensions page to install.

  5. Confirm a warning displays:

    Read and change all your data on the websites you visit
    Display notifications
    
  6. Click Add.

  7. Verify you have version 2.0 of Page Redder now installed.

Updating Permissions - No Warning

  1. Copy the content from manifest2.json into manifest.json and save the file. This adds new manifest permissions of webRequestBlocking, storage, along with a new content_script.
  2. Click Pack Extension.
  3. Select the source folder.
  4. Click Browse next to the Private key option and select the .pem file from your desktop.
  5. Click Pack Extension.
  6. Drag and drop the .crx file into the Chrome extensions page to install.
  7. Verify you have version 2.1 of Page Redder now installed with NO warning displayed.

Updating Permissions - Warning

  1. Copy the content from manifest3.json into manifest.json and save the file. This adds new manifest permission of privacy.

  2. Click Pack Extension.

  3. Select the source folder.

  4. Click Browse next to the Private key option and select the .pem file from your desktop.

  5. Click Pack Extension.

  6. Drag and drop the .crx file into the Chrome extensions page to install.

  7. Confirm a warning displays saying the extension has been disabled because it requires more permissions:

    Read and change all your data on the websites you visit
    Display notifications
    Change your privacy-related settings
    

Adding the new permissions webRequestBlocking and storage did NOT trigger a permission update warning. Nor did adding the second content script. However, adding the privacy permission triggers a warning.

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!');
chrome.tabs.executeScript({
code: 'document.body.style.backgroundColor="red"'
});
});
document.addEventListener("click", function() {
alert('hello 1!');
}, false);
document.addEventListener("click", function() {
alert('hello 2!');
}, false);
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.0",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": "Make this page red"
},
"permissions": [
"tabs",
"browsingData",
"notifications",
"webRequest",
"webNavigation",
"http://*/",
"https://*/"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content1.js"],
"run_at": "document_start"
}
],
"manifest_version": 2
}
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.0",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": "Make this page red"
},
"permissions": [
"tabs",
"browsingData",
"notifications",
"webRequest",
"webNavigation",
"http://*/",
"https://*/"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content1.js"],
"run_at": "document_start"
}
],
"manifest_version": 2
}
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.1",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": "Make this page red"
},
"permissions": [
"tabs",
"browsingData",
"notifications",
"webRequest",
"webNavigation",
"webRequestBlocking",
"storage",
"http://*/",
"https://*/"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content1.js"],
"run_at": "document_start"
},
{
"matches": ["http://*/*", "https://*/*"],
"css": ["style.css"],
"js": ["content2.js"],
"run_at": "document_end"
}
],
"manifest_version": 2
}
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.2",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": "Make this page red"
},
"permissions": [
"tabs",
"browsingData",
"notifications",
"webRequest",
"webNavigation",
"webRequestBlocking",
"storage",
"http://*/",
"https://*/",
"privacy"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content1.js"],
"run_at": "document_start"
},
{
"matches": ["http://*/*", "https://*/*"],
"css": ["style.css"],
"js": ["content2.js"],
"run_at": "document_end"
}
],
"manifest_version": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment