Skip to content

Commit

Permalink
pretty print (GoogleChrome#895)
Browse files Browse the repository at this point in the history
* added json for prettier, npm run prettier in lint-staged
  • Loading branch information
benjaminloerincz authored May 1, 2023
1 parent e09fc71 commit dc5d34f
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 92 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ cd chrome-extensions-samples
# install dependencies
npm install
```

### Writing a README

All new code samples or samples updated from Manifest V2 should include a README file. Please copy the [provided template](./README-template.md) into your sample's folder and follow the instructions therein.
1 change: 0 additions & 1 deletion README-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ _To create a README for your sample_
1. _Enter the requested information below._
1. _Delete all intructions._


_For API samples use the name of the API. For example, a sample about the `chrome.declarativeNetRequest` would simply be called "chrome.declarativeNetRequest". (Do not use special formatting in headings.) For functional samples, the title should be what the sample demonstrates_

# Title
Expand Down
2 changes: 1 addition & 1 deletion api-samples/contextMenus/basic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.7",
"permissions": ["contextMenus"],
"background": {
"service_worker": "sample.js"
"service_worker": "sample.js"
},
"manifest_version": 3
}
23 changes: 10 additions & 13 deletions api-samples/declarativeNetRequest/no-cookies/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
"description": "Removes 'Cookie' headers.",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback"
],
"host_permissions": [
"<all_urls>"
],
"permissions": ["declarativeNetRequest", "declarativeNetRequestFeedback"],
"host_permissions": ["<all_urls>"],
"background": {
"service_worker": "service-worker.js"
},
"declarative_net_request" : {
"rule_resources" : [{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}]
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}
]
}
}
4 changes: 1 addition & 3 deletions api-samples/declarativeNetRequest/no-cookies/rules_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"priority": 1,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{ "header": "cookie", "operation": "remove" }
]
"requestHeaders": [{ "header": "cookie", "operation": "remove" }]
},
"condition": {
"urlFilter": "|*?no-cookies=1",
Expand Down
19 changes: 9 additions & 10 deletions api-samples/declarativeNetRequest/url-blocker/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
"background": {
"service_worker": "service_worker.js"
},
"declarative_net_request" : {
"rule_resources" : [{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}]
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}
]
},
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback"
]
"permissions": ["declarativeNetRequest", "declarativeNetRequestFeedback"]
}
10 changes: 5 additions & 5 deletions api-samples/declarativeNetRequest/url-blocker/rules_1.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"id" : 1,
"id": 1,
"priority": 1,
"action" : { "type" : "block" },
"condition" : {
"urlFilter" : "||example.com",
"resourceTypes" : ["main_frame"]
"action": { "type": "block" },
"condition": {
"urlFilter": "||example.com",
"resourceTypes": ["main_frame"]
}
}
]
18 changes: 9 additions & 9 deletions api-samples/declarativeNetRequest/url-redirect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"background": {
"service_worker": "service_worker.js"
},
"declarative_net_request" : {
"rule_resources" : [{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}]
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}
]
},
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback",
"declarativeNetRequestWithHostAccess"
],
"host_permissions": [
"https://developer.chrome.com/"
]
"host_permissions": ["https://developer.chrome.com/"]
}
30 changes: 20 additions & 10 deletions api-samples/declarativeNetRequest/url-redirect/rules_1.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
[
{
"id" : 1,
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://developer.chrome.com/docs/extensions/mv3/intro/" }
"redirect": {
"url": "https://developer.chrome.com/docs/extensions/mv3/intro/"
}
},
"condition": {
"urlFilter": "https://developer.chrome.com/docs/extensions/mv2/",
"resourceTypes": ["main_frame"]
}
},
{
"id" : 2,
"id": 2,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/action/" }
"redirect": {
"url": "https://developer.chrome.com/docs/extensions/reference/action/"
}
},
"condition": {
"urlFilter": "https://developer.chrome.com/docs/extensions/reference/browserAction/",
"resourceTypes": ["main_frame"]
}
},
{
"id" : 3,
"id": 3,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" }
"redirect": {
"url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/"
}
},
"condition": {
"urlFilter": "https://developer.chrome.com/docs/extensions/reference/declarativeWebRequest/",
"resourceTypes": ["main_frame"]
}
},
{
"id" : 4,
"id": 4,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/action/" }
"redirect": {
"url": "https://developer.chrome.com/docs/extensions/reference/action/"
}
},
"condition": {
"urlFilter": "https://developer.chrome.com/docs/extensions/reference/pageAction/",
"resourceTypes": ["main_frame"]
}
},
{
"id" : 5,
"id": 5,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/" }
"redirect": {
"url": "https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/"
}
},
"condition": {
"urlFilter": "https://developer.chrome.com/docs/extensions/reference/webRequest/",
Expand Down
6 changes: 3 additions & 3 deletions api-samples/printing/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# chrome.printing

This sample demonstrates all four methods of the `chrome.printing` namespace.
This sample demonstrates all four methods of the `chrome.printing` namespace.

## Overview

The `chrome.printing` namespace only works on ChromeOS. The sample demonstrates how to get a list of available printers and display it to a user. A 'Print' button sends a sample PDF to the selected printer and makes a 'Cancel Printing' visible. This button is visible while the print job's status is `"PENDING"` or `"IN_PROGRESS"`. Note that on some systems, the print job is passed to the printer so quickly that you may never see the 'Cancel Printing' button.

Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation.
Calling `submitJob()` triggers a dialog box asking the user to confirm printing. Use the [`PrintingAPIExtensionsAllowlist`](https://chromeenterprise.google/policies/#PrintingAPIExtensionsAllowlist") policy to bypass confirmation.

## Implementation Notes

Note that the `submitJob()` function throws an error when returning a promise ([crbug: 1422837](https://bugs.chromium.org/p/chromium/issues/detail?id=1422837)).
Note that the `submitJob()` function throws an error when returning a promise ([crbug: 1422837](https://bugs.chromium.org/p/chromium/issues/detail?id=1422837)).
10 changes: 2 additions & 8 deletions api-samples/scripting/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
"background": {
"service_worker": "sw.js"
},
"permissions": [
"scripting",
"webNavigation",
"storage"
],
"host_permissions": [
"https://example.com/*"
],
"permissions": ["scripting", "webNavigation", "storage"],
"host_permissions": ["https://example.com/*"],
"action": {}
}
31 changes: 16 additions & 15 deletions functional-samples/sample.catifier/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "Catifier",
"version": "1.0",
"description": "Replace every image by a cat's image in a website you visit",
"permissions": ["declarativeNetRequest"],
"host_permissions": ["<all_urls>"],
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}]
},

"manifest_version": 3
}
"name": "Catifier",
"version": "1.0",
"description": "Replace every image by a cat's image in a website you visit",
"permissions": ["declarativeNetRequest"],
"host_permissions": ["<all_urls>"],
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}
]
},
"manifest_version": 3
}
34 changes: 22 additions & 12 deletions functional-samples/sample.catifier/rules.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
[
{
"id": 1,
"priority": 100,
"action": { "type": "redirect", "redirect": { "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" } },
"condition": {"urlFilter": "*.jpeg", "resourceType": ["image"]}
{
"id": 1,
"priority": 100,
"action": {
"type": "redirect",
"redirect": {
"url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg"
}
},
{
"id": 2,
"priority": 100,
"action": { "type": "redirect", "redirect": { "url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg" } },
"condition": {"urlFilter": "*.jpg", "resourceType": ["image"]}
}
]
"condition": { "urlFilter": "*.jpeg", "resourceType": ["image"] }
},
{
"id": 2,
"priority": 100,
"action": {
"type": "redirect",
"redirect": {
"url": "https://i.chzbgr.com/completestore/12/8/23/S__rxG9hIUK4sNuMdTIY9w2.jpg"
}
},
"condition": { "urlFilter": "*.jpg", "resourceType": ["image"] }
}
]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"description": "Official samples for Chrome Extensions and the Chrome Apps platform.",
"scripts": {
"prettier": "npx prettier **/*.{md,html} -w",
"prettier": "npx prettier **/*.{md,html,json} -w",
"lint": "eslint **/*.js",
"lint:fix": "npm run lint -- --fix",
"prepare": "husky install"
Expand Down Expand Up @@ -33,7 +33,7 @@
"**/*.js": [
"npx eslint --fix"
],
"**/*.{md,html}": [
"**/*.{md,html,json}": [
"npx prettier --write"
]
}
Expand Down

0 comments on commit dc5d34f

Please sign in to comment.