Skip to content

Commit ea5887c

Browse files
authored
Add vite template files (GoogleChromeLabs#2)
* Commit vite template files * Update - created a new icon, main ts script now handles both online and offline mode, rendering icons based on internet connection * Update package.json * Update: Fixed null check in .ts script, removed redundant stylesheet rules, configured autobuild with rollup-plugin-webbundle, updated README to reflect changes * Updated README.md, updated vite.config.js to build based on KEY_PATH instead of KEY, added prettier config file * Update vite-iwa-template/README.md Co-authored-by: Zgroza (Luke Klimek) <zgroza@google.com> * Added .md line wrapping
1 parent ac78d40 commit ea5887c

13 files changed

Lines changed: 1855 additions & 0 deletions

File tree

vite-iwa-template/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
.env
15+
16+
# Editor directories and files
17+
.vscode/*
18+
!.vscode/extensions.json
19+
.idea
20+
.DS_Store
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?
26+
27+
#Keys and bundles
28+
*.pem
29+
*.wbn
30+
*.swbn

vite-iwa-template/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 4,
4+
"proseWrap": "always"
5+
}

vite-iwa-template/README.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
## Prerequisites
2+
3+
- Google Chrome 120+
4+
5+
- openssl
6+
7+
- npm
8+
9+
## Using this repository
10+
11+
Clone this repository:
12+
13+
git clone ADD_LINK_HERE
14+
15+
cd iwa_vite_template
16+
17+
npm install
18+
19+
Open Google Chrome, go to `chrome://flags` and enable
20+
21+
chrome://flags/#enable-isolated-web-app-dev-mode
22+
23+
chrome://flags/#enable-isolated-web-apps
24+
25+
Once enabled, and chrome is restarted, go to `chrome://web-app-internals`, the web app internals
26+
page. This page shows you the web apps you have installed, including Isolated Web Apps and
27+
Progressive Web Apps, with details for each.
28+
29+
You'll know everything is correct if you see the "Isolated Web Apps" section at the top of the page.
30+
31+
### Installing the IWA through the dev proxy
32+
33+
Run:
34+
35+
`npm run dev`
36+
37+
Then, navigate to:
38+
39+
`chrome://web-app-internals`
40+
41+
Look for a field called "Install IWA via Dev Mode Proxy", type in your localhost url, then click
42+
Install
43+
44+
If everything installed correctly, you should see
45+
46+
Installing IWA: http://localhost:PORT/ successfully installed
47+
48+
Congratulations! You have installed your very own isolated web app
49+
50+
_Note: If your development server shuts down or is unreachable, you won't be able to access or
51+
install your Isolated Web App_
52+
53+
### Installing the IWA through a Signed Web Bundle
54+
55+
If you want to install your IWA through a .swbn file, you will need to generate a signing key, use
56+
openssl to generate and encrypt a Ed25519 or ECDSA P-256 key
57+
58+
#Generate an unencrypted Ed25519 key
59+
60+
openssl genpkey -algorithm Ed25519 -out private_key.pem
61+
62+
#Or Generate an unencrypted ECDSA P-256 key
63+
64+
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
65+
66+
#Encrypt the private key. Using a strong passphrase (which you will be
67+
#prompted for) is highly recommended to protect the key from unauthorized
68+
#use if the file is ever compromised.
69+
70+
openssl pkcs8 -in private_key.pem -topk8 -out encrypted_key.pem
71+
72+
#Remove the unencrypted key
73+
74+
rm private_key.pem
75+
76+
Next, create a .env file containing:
77+
78+
PRIVATE_KEY_PATH='PATH_TO_YOUR_ENCRYPTED_KEY'
79+
PRIVATE_KEY_PASSWORD='YOUR_KEY_PASSWORD'
80+
NODE_ENV='YOUR_ENVIROMENT_MODE'
81+
PORT=YOUR_PORT
82+
83+
_Note: NODE_ENV must be set to 'production' to make the build run._
84+
85+
_Note: If you don't specify PORT, the app will fall back to default value (4321)_
86+
87+
Next, you need to build your IWA by running
88+
89+
npm run build
90+
91+
This process will generate:
92+
93+
- A .swbn file named iwa-template.swbn in the /dist folder.
94+
- Your Web Bundle ID, displayed in the terminal
95+
96+
Navigate to `chrome://web-app-internals`, look for "Install IWA from Signed Web Bundle" field, click
97+
"Select File", upload your .swbn file.
98+
99+
If everything went correctly, you should see a field:
100+
101+
Installing IWA: successfully installed (Web Bundle ID:
102+
slu74sbybztfypa43w7f7rd34cbhautjcrfegz5lbow7vmwjojbqaaic).
103+
104+
_Note: Your web bundle ID will look differently, this is just an example_
105+
106+
Since IWA are using a different schema `isolated-app://` instead of `https://`, you can access it by
107+
pasting `isolated-app://your-web-bundle-id` in Chrome, or by running it like any other app on your
108+
computer.
109+
110+
### Personalizing this template
111+
112+
- How do I change the icon?
113+
114+
Navigate to /public/images/, change icon file, and update /public/.well-known/manifest.webmanifest
115+
"icons" field accordingly.
116+
117+
_Note: Isolated Web Apps require at least one icon of 144x144px size._
118+
119+
Related information:
120+
[Define your app icons - MDN Docs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/How_to/Define_app_icons)
121+
122+
- Updating the Manifest
123+
124+
Isolated Web Apps share the same
125+
[Manifest Properties](https://web.dev/articles/add-manifest#manifest-properties) as Progressive Web
126+
Apps, with some slight variations, see:
127+
[Isolated Web Apps explainer - Web App manifest section](https://chromeos.dev/en/web/isolated-web-apps)
128+
129+
There are two fields that should be included, `version` and `update_manifest_url`
130+
131+
1. `version` - Required for Isolated Web Apps. A string consisting of one or more integers separated
132+
by a dot (.). Your version can be something simple like 1, 2, 3, etc…, or something complex like
133+
[SemVer](https://semver.org/)⁠ (1.2.3).
134+
135+
2. `update_manifest_url` - Optional, but recommended field that points to an HTTPS URL (or localhost
136+
for testing) where a Web Application Update Manifest can be retrieved.
137+
138+
- How to add API Permissions?
139+
140+
By default, Chrome blocks all permission requests from IWAs. You can opt-in to permission policies you need by specifying
141+
a `permissions_policy` field in your manifest.
142+
143+
_Note: Adding a permission here does not automatically grant it, it just makes it avaliable to be
144+
granted, when a request for that capacity is made._
145+
146+
#permission policy example
147+
"permissions_policy": {
148+
"geolocation": [ "self", "https://map.example.com" ],
149+
"direct-sockets": ["self"],
150+
"controlled-frame": ["self"]
151+
}
152+
153+
Related Information
154+
155+
- [Permissions Policy - MDN Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Permissions_Policy#allowlists)
156+
- [Permissions Policy header - MDN Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Permissions_Policy#allowlists)
157+
- [Web Application Manifest - MDN Docs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest)
158+
159+
### Related Information
160+
161+
- [Isolated Web Apps Explainer](https://chromeos.dev/en/web/isolated-web-apps)
162+
- [IWA Kitchen Sink](https://github.com/chromeos/iwa-sink)
163+
- [IWA Telnet Client](https://github.com/GoogleChromeLabs/telnet-client/tree/main)
164+
- [IWA Smartcard Demo](https://github.com/GoogleChromeLabs/web-smartcard-demo/tree/main)

vite-iwa-template/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<!--
3+
Copyright 2025 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<html lang="en">
19+
<head>
20+
<meta charset="UTF-8" />
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
22+
</head>
23+
<body>
24+
<div id="app"></div>
25+
<script type="module" src="/src/main.ts"></script>
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)