stage-browser 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -2
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +90 -0
- package/dist/main/main.js +279 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +155 -0
- package/dist/main/selftest.js +490 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +68 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +33 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +653 -0
- package/dist/ui/index.html +41 -0
- package/dist/ui/mock.js +479 -0
- package/dist/ui/newtab.html +69 -0
- package/dist/ui/styles.css +410 -0
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +64 -4
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
// src/browser/index.ts
|
|
2
|
+
import { app as app4, session as electronSession3 } from "electron";
|
|
3
|
+
import * as path5 from "node:path";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
|
|
7
|
+
// src/browser/api.ts
|
|
8
|
+
import debug3 from "debug";
|
|
9
|
+
import { app as app2, BrowserWindow, ipcMain, nativeImage } from "electron";
|
|
10
|
+
|
|
11
|
+
// src/browser/utils.ts
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { app, net } from "electron";
|
|
14
|
+
var fetch = (
|
|
15
|
+
// Prefer Node's fetch until net.fetch crash is fixed
|
|
16
|
+
// https://github.com/electron/electron/pull/45050
|
|
17
|
+
globalThis.fetch || net?.fetch || (() => {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"electron-chrome-web-store: Missing fetch API. Please upgrade Electron or Node."
|
|
20
|
+
);
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
var getChromeVersion = () => process.versions.chrome || "131.0.6778.109";
|
|
24
|
+
function compareVersions(version1, version2) {
|
|
25
|
+
const v1 = version1.split(".").map(Number);
|
|
26
|
+
const v2 = version2.split(".").map(Number);
|
|
27
|
+
for (let i = 0; i < 3; i++) {
|
|
28
|
+
if (v1[i] > v2[i]) return 1;
|
|
29
|
+
if (v1[i] < v2[i]) return -1;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
var getDefaultExtensionsPath = () => path.join(app.getPath("userData"), "Extensions");
|
|
34
|
+
|
|
35
|
+
// src/common/constants.ts
|
|
36
|
+
var ExtensionInstallStatus = {
|
|
37
|
+
BLACKLISTED: "blacklisted",
|
|
38
|
+
BLOCKED_BY_POLICY: "blocked_by_policy",
|
|
39
|
+
CAN_REQUEST: "can_request",
|
|
40
|
+
CORRUPTED: "corrupted",
|
|
41
|
+
CUSTODIAN_APPROVAL_REQUIRED: "custodian_approval_required",
|
|
42
|
+
CUSTODIAN_APPROVAL_REQUIRED_FOR_INSTALLATION: "custodian_approval_required_for_installation",
|
|
43
|
+
DEPRECATED_MANIFEST_VERSION: "deprecated_manifest_version",
|
|
44
|
+
DISABLED: "disabled",
|
|
45
|
+
ENABLED: "enabled",
|
|
46
|
+
FORCE_INSTALLED: "force_installed",
|
|
47
|
+
INSTALLABLE: "installable",
|
|
48
|
+
REQUEST_PENDING: "request_pending",
|
|
49
|
+
TERMINATED: "terminated"
|
|
50
|
+
};
|
|
51
|
+
var MV2DeprecationStatus = {
|
|
52
|
+
INACTIVE: "inactive",
|
|
53
|
+
SOFT_DISABLE: "soft_disable",
|
|
54
|
+
WARNING: "warning"
|
|
55
|
+
};
|
|
56
|
+
var Result = {
|
|
57
|
+
ALREADY_INSTALLED: "already_installed",
|
|
58
|
+
BLACKLISTED: "blacklisted",
|
|
59
|
+
BLOCKED_BY_POLICY: "blocked_by_policy",
|
|
60
|
+
BLOCKED_FOR_CHILD_ACCOUNT: "blocked_for_child_account",
|
|
61
|
+
FEATURE_DISABLED: "feature_disabled",
|
|
62
|
+
ICON_ERROR: "icon_error",
|
|
63
|
+
INSTALL_ERROR: "install_error",
|
|
64
|
+
INSTALL_IN_PROGRESS: "install_in_progress",
|
|
65
|
+
INVALID_ICON_URL: "invalid_icon_url",
|
|
66
|
+
INVALID_ID: "invalid_id",
|
|
67
|
+
LAUNCH_IN_PROGRESS: "launch_in_progress",
|
|
68
|
+
MANIFEST_ERROR: "manifest_error",
|
|
69
|
+
MISSING_DEPENDENCIES: "missing_dependencies",
|
|
70
|
+
SUCCESS: "success",
|
|
71
|
+
UNKNOWN_ERROR: "unknown_error",
|
|
72
|
+
UNSUPPORTED_EXTENSION_TYPE: "unsupported_extension_type",
|
|
73
|
+
USER_CANCELLED: "user_cancelled",
|
|
74
|
+
USER_GESTURE_REQUIRED: "user_gesture_required"
|
|
75
|
+
};
|
|
76
|
+
var WebGlStatus = {
|
|
77
|
+
WEBGL_ALLOWED: "webgl_allowed",
|
|
78
|
+
WEBGL_BLOCKED: "webgl_blocked"
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/browser/installer.ts
|
|
82
|
+
import * as fs2 from "node:fs";
|
|
83
|
+
import * as os from "node:os";
|
|
84
|
+
import * as path3 from "node:path";
|
|
85
|
+
import { Readable } from "node:stream";
|
|
86
|
+
import { pipeline } from "node:stream/promises";
|
|
87
|
+
import { session as electronSession } from "electron";
|
|
88
|
+
import AdmZip from "adm-zip";
|
|
89
|
+
import debug2 from "debug";
|
|
90
|
+
import Pbf from "pbf";
|
|
91
|
+
|
|
92
|
+
// src/browser/crx3.ts
|
|
93
|
+
function readCrxFileHeader(pbf, end) {
|
|
94
|
+
return pbf.readFields(
|
|
95
|
+
readCrxFileHeaderField,
|
|
96
|
+
{
|
|
97
|
+
sha256_with_rsa: [],
|
|
98
|
+
sha256_with_ecdsa: [],
|
|
99
|
+
verified_contents: void 0,
|
|
100
|
+
signed_header_data: void 0
|
|
101
|
+
},
|
|
102
|
+
end
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
function readCrxFileHeaderField(tag, obj, pbf) {
|
|
106
|
+
if (tag === 2) obj.sha256_with_rsa.push(readAsymmetricKeyProof(pbf, pbf.readVarint() + pbf.pos));
|
|
107
|
+
else if (tag === 3)
|
|
108
|
+
obj.sha256_with_ecdsa.push(readAsymmetricKeyProof(pbf, pbf.readVarint() + pbf.pos));
|
|
109
|
+
else if (tag === 4) obj.verified_contents = pbf.readBytes();
|
|
110
|
+
else if (tag === 1e4) obj.signed_header_data = pbf.readBytes();
|
|
111
|
+
}
|
|
112
|
+
function readAsymmetricKeyProof(pbf, end) {
|
|
113
|
+
return pbf.readFields(
|
|
114
|
+
readAsymmetricKeyProofField,
|
|
115
|
+
{ public_key: void 0, signature: void 0 },
|
|
116
|
+
end
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
function readAsymmetricKeyProofField(tag, obj, pbf) {
|
|
120
|
+
if (tag === 1) obj.public_key = pbf.readBytes();
|
|
121
|
+
else if (tag === 2) obj.signature = pbf.readBytes();
|
|
122
|
+
}
|
|
123
|
+
function readSignedData(pbf, end) {
|
|
124
|
+
return pbf.readFields(readSignedDataField, { crx_id: void 0 }, end);
|
|
125
|
+
}
|
|
126
|
+
function readSignedDataField(tag, obj, pbf) {
|
|
127
|
+
if (tag === 1) obj.crx_id = pbf.readBytes();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/browser/id.ts
|
|
131
|
+
import { createHash } from "node:crypto";
|
|
132
|
+
function convertHexadecimalToIDAlphabet(id) {
|
|
133
|
+
let result = "";
|
|
134
|
+
for (const ch of id) {
|
|
135
|
+
const val = parseInt(ch, 16);
|
|
136
|
+
if (!isNaN(val)) {
|
|
137
|
+
result += String.fromCharCode("a".charCodeAt(0) + val);
|
|
138
|
+
} else {
|
|
139
|
+
result += "a";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
function generateIdFromHash(hash) {
|
|
145
|
+
const hashedId = hash.subarray(0, 16).toString("hex");
|
|
146
|
+
return convertHexadecimalToIDAlphabet(hashedId);
|
|
147
|
+
}
|
|
148
|
+
function generateId(input) {
|
|
149
|
+
const hash = createHash("sha256").update(input, "base64").digest();
|
|
150
|
+
return generateIdFromHash(hash);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/browser/loader.ts
|
|
154
|
+
import * as fs from "node:fs";
|
|
155
|
+
import * as path2 from "node:path";
|
|
156
|
+
import debug from "debug";
|
|
157
|
+
var d = debug("electron-chrome-web-store:loader");
|
|
158
|
+
var manifestExists = async (dirPath) => {
|
|
159
|
+
if (!dirPath) return false;
|
|
160
|
+
const manifestPath = path2.join(dirPath, "manifest.json");
|
|
161
|
+
try {
|
|
162
|
+
return (await fs.promises.stat(manifestPath)).isFile();
|
|
163
|
+
} catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
async function extensionSearch(dirPath, depth = 0) {
|
|
168
|
+
if (depth >= 2) return [];
|
|
169
|
+
const results = [];
|
|
170
|
+
const dirEntries = await fs.promises.readdir(dirPath, { withFileTypes: true });
|
|
171
|
+
for (const entry of dirEntries) {
|
|
172
|
+
if (entry.isDirectory()) {
|
|
173
|
+
if (await manifestExists(path2.join(dirPath, entry.name))) {
|
|
174
|
+
results.push(path2.join(dirPath, entry.name));
|
|
175
|
+
} else {
|
|
176
|
+
results.push(...await extensionSearch(path2.join(dirPath, entry.name), depth + 1));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return results;
|
|
181
|
+
}
|
|
182
|
+
async function discoverExtensions(extensionsPath) {
|
|
183
|
+
try {
|
|
184
|
+
const stat = await fs.promises.stat(extensionsPath);
|
|
185
|
+
if (!stat.isDirectory()) {
|
|
186
|
+
d("%s is not a directory", extensionsPath);
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
} catch {
|
|
190
|
+
d("%s does not exist", extensionsPath);
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
const extensionDirectories = await extensionSearch(extensionsPath);
|
|
194
|
+
const results = [];
|
|
195
|
+
for (const extPath of extensionDirectories.filter(Boolean)) {
|
|
196
|
+
try {
|
|
197
|
+
const manifestPath = path2.join(extPath, "manifest.json");
|
|
198
|
+
const manifestJson = (await fs.promises.readFile(manifestPath)).toString();
|
|
199
|
+
const manifest = JSON.parse(manifestJson);
|
|
200
|
+
const result = manifest.key ? {
|
|
201
|
+
type: "store",
|
|
202
|
+
path: extPath,
|
|
203
|
+
manifest,
|
|
204
|
+
id: generateId(manifest.key)
|
|
205
|
+
} : {
|
|
206
|
+
type: "unpacked",
|
|
207
|
+
path: extPath,
|
|
208
|
+
manifest
|
|
209
|
+
};
|
|
210
|
+
results.push(result);
|
|
211
|
+
} catch (e) {
|
|
212
|
+
console.error(e);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return results;
|
|
216
|
+
}
|
|
217
|
+
function filterOutdatedExtensions(extensions) {
|
|
218
|
+
const uniqueExtensions = [];
|
|
219
|
+
const storeExtMap = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const ext of extensions) {
|
|
221
|
+
if (ext.type === "unpacked") {
|
|
222
|
+
uniqueExtensions.push(ext);
|
|
223
|
+
} else if (!storeExtMap.has(ext.id)) {
|
|
224
|
+
storeExtMap.set(ext.id, ext);
|
|
225
|
+
} else {
|
|
226
|
+
const latestExt = storeExtMap.get(ext.id);
|
|
227
|
+
if (compareVersions(latestExt.manifest.version, ext.manifest.version) < 0) {
|
|
228
|
+
storeExtMap.set(ext.id, ext);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
storeExtMap.forEach((ext) => uniqueExtensions.push(ext));
|
|
233
|
+
return uniqueExtensions;
|
|
234
|
+
}
|
|
235
|
+
async function loadAllExtensions(session, extensionsPath, options = {}) {
|
|
236
|
+
const sessionExtensions = session.extensions || session;
|
|
237
|
+
let extensions = await discoverExtensions(extensionsPath);
|
|
238
|
+
extensions = filterOutdatedExtensions(extensions);
|
|
239
|
+
d("discovered %d extension(s) in %s", extensions.length, extensionsPath);
|
|
240
|
+
for (const ext of extensions) {
|
|
241
|
+
try {
|
|
242
|
+
let extension;
|
|
243
|
+
if (ext.type === "store") {
|
|
244
|
+
const existingExt = sessionExtensions.getExtension(ext.id);
|
|
245
|
+
if (existingExt) {
|
|
246
|
+
d("skipping loading existing extension %s", ext.id);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
d("loading extension %s", `${ext.id}@${ext.manifest.version}`);
|
|
250
|
+
extension = await sessionExtensions.loadExtension(ext.path);
|
|
251
|
+
} else if (options.allowUnpacked) {
|
|
252
|
+
d("loading unpacked extension %s", ext.path);
|
|
253
|
+
extension = await sessionExtensions.loadExtension(ext.path);
|
|
254
|
+
}
|
|
255
|
+
if (extension && extension.manifest.manifest_version === 3 && extension.manifest.background?.service_worker) {
|
|
256
|
+
const scope = `chrome-extension://${extension.id}`;
|
|
257
|
+
await session.serviceWorkers.startWorkerForScope(scope).catch(() => {
|
|
258
|
+
console.error(`Failed to start worker for extension ${extension.id}`);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error(`Failed to load extension from ${ext.path}`);
|
|
263
|
+
console.error(error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async function findExtensionInstall(extensionId, extensionsPath) {
|
|
268
|
+
const extensionPath = path2.join(extensionsPath, extensionId);
|
|
269
|
+
let extensions = await discoverExtensions(extensionPath);
|
|
270
|
+
extensions = filterOutdatedExtensions(extensions);
|
|
271
|
+
return extensions.length > 0 ? extensions[0] : null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/browser/installer.ts
|
|
275
|
+
var d2 = debug2("electron-chrome-web-store:installer");
|
|
276
|
+
function getExtensionCrxURL(extensionId) {
|
|
277
|
+
const url = new URL("https://clients2.google.com/service/update2/crx");
|
|
278
|
+
url.searchParams.append("response", "redirect");
|
|
279
|
+
url.searchParams.append("acceptformat", ["crx2", "crx3"].join(","));
|
|
280
|
+
const x = new URLSearchParams();
|
|
281
|
+
x.append("id", extensionId);
|
|
282
|
+
x.append("uc", "");
|
|
283
|
+
url.searchParams.append("x", x.toString());
|
|
284
|
+
url.searchParams.append("prodversion", getChromeVersion());
|
|
285
|
+
return url.toString();
|
|
286
|
+
}
|
|
287
|
+
function parseCrx(buffer) {
|
|
288
|
+
const magicNumber = buffer.toString("utf8", 0, 4);
|
|
289
|
+
if (magicNumber !== "Cr24") {
|
|
290
|
+
throw new Error("Invalid CRX format");
|
|
291
|
+
}
|
|
292
|
+
const version = buffer.readUInt32LE(4);
|
|
293
|
+
const headerSize = buffer.readUInt32LE(8);
|
|
294
|
+
const header = buffer.subarray(12, 12 + headerSize);
|
|
295
|
+
const contents = buffer.subarray(12 + headerSize);
|
|
296
|
+
let extensionId;
|
|
297
|
+
let publicKey;
|
|
298
|
+
if (version === 2) {
|
|
299
|
+
const pubKeyLength = buffer.readUInt32LE(8);
|
|
300
|
+
const sigLength = buffer.readUInt32LE(12);
|
|
301
|
+
publicKey = buffer.subarray(16, 16 + pubKeyLength);
|
|
302
|
+
extensionId = generateId(publicKey.toString("base64"));
|
|
303
|
+
} else {
|
|
304
|
+
const crxFileHeader = readCrxFileHeader(new Pbf(header));
|
|
305
|
+
const crxSignedData = readSignedData(new Pbf(crxFileHeader.signed_header_data));
|
|
306
|
+
const declaredCrxId = crxSignedData.crx_id ? convertHexadecimalToIDAlphabet(crxSignedData.crx_id.toString("hex")) : null;
|
|
307
|
+
if (!declaredCrxId) {
|
|
308
|
+
throw new Error("Invalid CRX signed data");
|
|
309
|
+
}
|
|
310
|
+
const keyProof = crxFileHeader.sha256_with_rsa.find((proof) => {
|
|
311
|
+
const crxId = proof.public_key ? generateId(proof.public_key.toString("base64")) : null;
|
|
312
|
+
return crxId === declaredCrxId;
|
|
313
|
+
});
|
|
314
|
+
if (!keyProof) {
|
|
315
|
+
throw new Error("Invalid CRX key");
|
|
316
|
+
}
|
|
317
|
+
extensionId = declaredCrxId;
|
|
318
|
+
publicKey = keyProof.public_key;
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
extensionId,
|
|
322
|
+
version,
|
|
323
|
+
header,
|
|
324
|
+
contents,
|
|
325
|
+
publicKey
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function unpackCrx(crx, destPath) {
|
|
329
|
+
const zip = new AdmZip(crx.contents);
|
|
330
|
+
zip.extractAllTo(destPath, true);
|
|
331
|
+
const manifestPath = path3.join(destPath, "manifest.json");
|
|
332
|
+
const manifestContent = await fs2.promises.readFile(manifestPath, "utf8");
|
|
333
|
+
const manifest = JSON.parse(manifestContent);
|
|
334
|
+
manifest.key = crx.publicKey.toString("base64");
|
|
335
|
+
await fs2.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
336
|
+
return manifest;
|
|
337
|
+
}
|
|
338
|
+
async function readCrx(crxPath) {
|
|
339
|
+
const crxBuffer = await fs2.promises.readFile(crxPath);
|
|
340
|
+
return parseCrx(crxBuffer);
|
|
341
|
+
}
|
|
342
|
+
async function downloadCrx(url, dest) {
|
|
343
|
+
const response = await fetch(url);
|
|
344
|
+
if (!response.ok) {
|
|
345
|
+
throw new Error("Failed to download extension");
|
|
346
|
+
}
|
|
347
|
+
const fileStream = fs2.createWriteStream(dest);
|
|
348
|
+
const downloadStream = Readable.fromWeb(response.body);
|
|
349
|
+
await pipeline(downloadStream, fileStream);
|
|
350
|
+
}
|
|
351
|
+
async function downloadExtensionFromURL(url, extensionsDir, expectedExtensionId) {
|
|
352
|
+
d2("downloading %s", url);
|
|
353
|
+
const installUuid = crypto.randomUUID();
|
|
354
|
+
const crxPath = path3.join(os.tmpdir(), `electron-cws-download_${installUuid}.crx`);
|
|
355
|
+
try {
|
|
356
|
+
await downloadCrx(url, crxPath);
|
|
357
|
+
const crx = await readCrx(crxPath);
|
|
358
|
+
if (expectedExtensionId && expectedExtensionId !== crx.extensionId) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
`CRX mismatches expected extension ID: ${expectedExtensionId} !== ${crx.extensionId}`
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
const unpackedPath = path3.join(extensionsDir, crx.extensionId, installUuid);
|
|
364
|
+
await fs2.promises.mkdir(unpackedPath, { recursive: true });
|
|
365
|
+
const manifest = await unpackCrx(crx, unpackedPath);
|
|
366
|
+
if (!manifest.version) {
|
|
367
|
+
throw new Error("Installed extension is missing manifest version");
|
|
368
|
+
}
|
|
369
|
+
const versionedPath = path3.join(extensionsDir, crx.extensionId, `${manifest.version}_0`);
|
|
370
|
+
await fs2.promises.rename(unpackedPath, versionedPath);
|
|
371
|
+
return versionedPath;
|
|
372
|
+
} finally {
|
|
373
|
+
await fs2.promises.rm(crxPath, { force: true });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async function downloadExtension(extensionId, extensionsDir) {
|
|
377
|
+
const url = getExtensionCrxURL(extensionId);
|
|
378
|
+
return await downloadExtensionFromURL(url, extensionsDir, extensionId);
|
|
379
|
+
}
|
|
380
|
+
async function installExtension(extensionId, opts = {}) {
|
|
381
|
+
d2("installing %s", extensionId);
|
|
382
|
+
const session = opts.session || electronSession.defaultSession;
|
|
383
|
+
const sessionExtensions = session.extensions || session;
|
|
384
|
+
const extensionsPath = opts.extensionsPath || getDefaultExtensionsPath();
|
|
385
|
+
const existingExtension = sessionExtensions.getExtension(extensionId);
|
|
386
|
+
if (existingExtension) {
|
|
387
|
+
d2("%s already loaded", extensionId);
|
|
388
|
+
return existingExtension;
|
|
389
|
+
}
|
|
390
|
+
const existingExtensionInfo = await findExtensionInstall(extensionId, extensionsPath);
|
|
391
|
+
if (existingExtensionInfo && existingExtensionInfo.type === "store") {
|
|
392
|
+
d2("%s already installed", extensionId);
|
|
393
|
+
return await sessionExtensions.loadExtension(
|
|
394
|
+
existingExtensionInfo.path,
|
|
395
|
+
opts.loadExtensionOptions
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
const extensionPath = await downloadExtension(extensionId, extensionsPath);
|
|
399
|
+
const extension = await sessionExtensions.loadExtension(extensionPath, opts.loadExtensionOptions);
|
|
400
|
+
d2("installed %s", extensionId);
|
|
401
|
+
return extension;
|
|
402
|
+
}
|
|
403
|
+
async function uninstallExtension(extensionId, opts = {}) {
|
|
404
|
+
d2("uninstalling %s", extensionId);
|
|
405
|
+
const session = opts.session || electronSession.defaultSession;
|
|
406
|
+
const sessionExtensions = session.extensions || session;
|
|
407
|
+
const extensionsPath = opts.extensionsPath || getDefaultExtensionsPath();
|
|
408
|
+
const extensions = sessionExtensions.getAllExtensions();
|
|
409
|
+
const existingExt = extensions.find((ext) => ext.id === extensionId);
|
|
410
|
+
if (existingExt) {
|
|
411
|
+
sessionExtensions.removeExtension(extensionId);
|
|
412
|
+
}
|
|
413
|
+
const extensionDir = path3.join(extensionsPath, extensionId);
|
|
414
|
+
try {
|
|
415
|
+
const stat = await fs2.promises.stat(extensionDir);
|
|
416
|
+
if (stat.isDirectory()) {
|
|
417
|
+
await fs2.promises.rm(extensionDir, { recursive: true, force: true });
|
|
418
|
+
}
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (error?.code !== "ENOENT") {
|
|
421
|
+
throw error;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/browser/api.ts
|
|
427
|
+
var d3 = debug3("electron-chrome-web-store:api");
|
|
428
|
+
var WEBSTORE_URL = "https://chromewebstore.google.com";
|
|
429
|
+
function getExtensionInfo(ext) {
|
|
430
|
+
const manifest = ext.manifest;
|
|
431
|
+
return {
|
|
432
|
+
description: manifest.description || "",
|
|
433
|
+
enabled: !manifest.disabled,
|
|
434
|
+
homepageUrl: manifest.homepage_url || "",
|
|
435
|
+
hostPermissions: manifest.host_permissions || [],
|
|
436
|
+
icons: Object.entries(manifest?.icons || {}).map(([size, url]) => ({
|
|
437
|
+
size: parseInt(size),
|
|
438
|
+
url: `chrome://extension-icon/${ext.id}/${size}/0`
|
|
439
|
+
})),
|
|
440
|
+
id: ext.id,
|
|
441
|
+
installType: "normal",
|
|
442
|
+
isApp: !!manifest.app,
|
|
443
|
+
mayDisable: true,
|
|
444
|
+
name: manifest.name,
|
|
445
|
+
offlineEnabled: !!manifest.offline_enabled,
|
|
446
|
+
optionsUrl: manifest.options_page ? `chrome-extension://${ext.id}/${manifest.options_page}` : "",
|
|
447
|
+
permissions: manifest.permissions || [],
|
|
448
|
+
shortName: manifest.short_name || manifest.name,
|
|
449
|
+
type: manifest.app ? "app" : "extension",
|
|
450
|
+
updateUrl: manifest.update_url || "",
|
|
451
|
+
version: manifest.version
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function getExtensionInstallStatus(state, extensionId, manifest) {
|
|
455
|
+
if (manifest && manifest.manifest_version < state.minimumManifestVersion) {
|
|
456
|
+
return ExtensionInstallStatus.DEPRECATED_MANIFEST_VERSION;
|
|
457
|
+
}
|
|
458
|
+
if (state.denylist?.has(extensionId)) {
|
|
459
|
+
return ExtensionInstallStatus.BLOCKED_BY_POLICY;
|
|
460
|
+
}
|
|
461
|
+
if (state.allowlist && !state.allowlist.has(extensionId)) {
|
|
462
|
+
return ExtensionInstallStatus.BLOCKED_BY_POLICY;
|
|
463
|
+
}
|
|
464
|
+
const sessionExtensions = state.session.extensions || state.session;
|
|
465
|
+
const extensions = sessionExtensions.getAllExtensions();
|
|
466
|
+
const extension = extensions.find((ext) => ext.id === extensionId);
|
|
467
|
+
if (!extension) {
|
|
468
|
+
return ExtensionInstallStatus.INSTALLABLE;
|
|
469
|
+
}
|
|
470
|
+
if (extension.manifest.disabled) {
|
|
471
|
+
return ExtensionInstallStatus.DISABLED;
|
|
472
|
+
}
|
|
473
|
+
return ExtensionInstallStatus.ENABLED;
|
|
474
|
+
}
|
|
475
|
+
async function beginInstall({ sender, senderFrame }, state, details) {
|
|
476
|
+
const extensionId = details.id;
|
|
477
|
+
try {
|
|
478
|
+
if (state.installing.has(extensionId)) {
|
|
479
|
+
return { result: Result.INSTALL_IN_PROGRESS };
|
|
480
|
+
}
|
|
481
|
+
let manifest;
|
|
482
|
+
try {
|
|
483
|
+
manifest = JSON.parse(details.manifest);
|
|
484
|
+
} catch {
|
|
485
|
+
return { result: Result.MANIFEST_ERROR };
|
|
486
|
+
}
|
|
487
|
+
const installStatus = getExtensionInstallStatus(state, extensionId, manifest);
|
|
488
|
+
switch (installStatus) {
|
|
489
|
+
case ExtensionInstallStatus.INSTALLABLE:
|
|
490
|
+
break;
|
|
491
|
+
// good to go
|
|
492
|
+
case ExtensionInstallStatus.BLOCKED_BY_POLICY:
|
|
493
|
+
return { result: Result.BLOCKED_BY_POLICY };
|
|
494
|
+
default: {
|
|
495
|
+
d3('unable to install extension %s with status "%s"', extensionId, installStatus);
|
|
496
|
+
return { result: Result.UNKNOWN_ERROR };
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
let iconUrl;
|
|
500
|
+
try {
|
|
501
|
+
iconUrl = new URL(details.iconUrl);
|
|
502
|
+
} catch {
|
|
503
|
+
return { result: Result.INVALID_ICON_URL };
|
|
504
|
+
}
|
|
505
|
+
let icon;
|
|
506
|
+
try {
|
|
507
|
+
const response = await fetch(iconUrl.href);
|
|
508
|
+
const imageBuffer = Buffer.from(await response.arrayBuffer());
|
|
509
|
+
icon = nativeImage.createFromBuffer(imageBuffer);
|
|
510
|
+
} catch {
|
|
511
|
+
return { result: Result.ICON_ERROR };
|
|
512
|
+
}
|
|
513
|
+
const browserWindow = BrowserWindow.fromWebContents(sender);
|
|
514
|
+
if (!senderFrame || senderFrame.isDestroyed()) {
|
|
515
|
+
return { result: Result.UNKNOWN_ERROR };
|
|
516
|
+
}
|
|
517
|
+
if (state.beforeInstall) {
|
|
518
|
+
const result = await state.beforeInstall({
|
|
519
|
+
id: extensionId,
|
|
520
|
+
localizedName: details.localizedName,
|
|
521
|
+
manifest,
|
|
522
|
+
icon,
|
|
523
|
+
frame: senderFrame,
|
|
524
|
+
browserWindow: browserWindow || void 0
|
|
525
|
+
});
|
|
526
|
+
if (typeof result !== "object" || typeof result.action !== "string") {
|
|
527
|
+
return { result: Result.UNKNOWN_ERROR };
|
|
528
|
+
} else if (result.action !== "allow") {
|
|
529
|
+
return { result: Result.USER_CANCELLED };
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
state.installing.add(extensionId);
|
|
533
|
+
await installExtension(extensionId, state);
|
|
534
|
+
return { result: Result.SUCCESS };
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.error("Extension installation failed:", error);
|
|
537
|
+
return {
|
|
538
|
+
result: Result.INSTALL_ERROR,
|
|
539
|
+
message: error instanceof Error ? error.message : String(error)
|
|
540
|
+
};
|
|
541
|
+
} finally {
|
|
542
|
+
state.installing.delete(extensionId);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
var handledIpcChannels = /* @__PURE__ */ new Map();
|
|
546
|
+
function registerWebStoreApi(webStoreState) {
|
|
547
|
+
const handle = (channel, handle2) => {
|
|
548
|
+
let handlersMap = handledIpcChannels.get(channel);
|
|
549
|
+
if (!handlersMap) {
|
|
550
|
+
handlersMap = /* @__PURE__ */ new Map();
|
|
551
|
+
handledIpcChannels.set(channel, handlersMap);
|
|
552
|
+
ipcMain.handle(channel, async function handleWebStoreIpc(event, ...args) {
|
|
553
|
+
d3("received %s", channel);
|
|
554
|
+
const senderOrigin = event.senderFrame?.origin;
|
|
555
|
+
if (!senderOrigin || !senderOrigin.startsWith(WEBSTORE_URL)) {
|
|
556
|
+
d3("ignoring webstore request from %s", senderOrigin);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const session = event.sender.session;
|
|
560
|
+
const handler = handlersMap?.get(session);
|
|
561
|
+
if (!handler) {
|
|
562
|
+
d3("no handler for session %s", session.storagePath);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const result = await handler(event, ...args);
|
|
566
|
+
d3("%s result", channel, result);
|
|
567
|
+
return result;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
handlersMap.set(webStoreState.session, handle2);
|
|
571
|
+
};
|
|
572
|
+
handle("chromeWebstore.beginInstall", async (event, details) => {
|
|
573
|
+
const { senderFrame } = event;
|
|
574
|
+
d3("beginInstall", details);
|
|
575
|
+
const result = await beginInstall(event, webStoreState, details);
|
|
576
|
+
if (result.result === Result.SUCCESS) {
|
|
577
|
+
queueMicrotask(() => {
|
|
578
|
+
const sessionExtensions = webStoreState.session.extensions || webStoreState.session;
|
|
579
|
+
const ext = sessionExtensions.getExtension(details.id);
|
|
580
|
+
if (ext && senderFrame && !senderFrame.isDestroyed()) {
|
|
581
|
+
try {
|
|
582
|
+
senderFrame.send("chrome.management.onInstalled", getExtensionInfo(ext));
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.error(error);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return result;
|
|
590
|
+
});
|
|
591
|
+
handle("chromeWebstore.completeInstall", async (event, id) => {
|
|
592
|
+
return Result.SUCCESS;
|
|
593
|
+
});
|
|
594
|
+
handle("chromeWebstore.enableAppLauncher", async (event, enable) => {
|
|
595
|
+
return true;
|
|
596
|
+
});
|
|
597
|
+
handle("chromeWebstore.getBrowserLogin", async () => {
|
|
598
|
+
return "";
|
|
599
|
+
});
|
|
600
|
+
handle("chromeWebstore.getExtensionStatus", async (_event, id, manifestJson) => {
|
|
601
|
+
const manifest = JSON.parse(manifestJson);
|
|
602
|
+
return getExtensionInstallStatus(webStoreState, id, manifest);
|
|
603
|
+
});
|
|
604
|
+
handle("chromeWebstore.getFullChromeVersion", async () => {
|
|
605
|
+
return {
|
|
606
|
+
version_number: process.versions.chrome,
|
|
607
|
+
app_name: app2.getName()
|
|
608
|
+
};
|
|
609
|
+
});
|
|
610
|
+
handle("chromeWebstore.getIsLauncherEnabled", async () => {
|
|
611
|
+
return true;
|
|
612
|
+
});
|
|
613
|
+
handle("chromeWebstore.getMV2DeprecationStatus", async () => {
|
|
614
|
+
return webStoreState.minimumManifestVersion > 2 ? MV2DeprecationStatus.SOFT_DISABLE : MV2DeprecationStatus.INACTIVE;
|
|
615
|
+
});
|
|
616
|
+
handle("chromeWebstore.getReferrerChain", async () => {
|
|
617
|
+
return "EgIIAA==";
|
|
618
|
+
});
|
|
619
|
+
handle("chromeWebstore.getStoreLogin", async () => {
|
|
620
|
+
return "";
|
|
621
|
+
});
|
|
622
|
+
handle("chromeWebstore.getWebGLStatus", async () => {
|
|
623
|
+
await app2.getGPUInfo("basic");
|
|
624
|
+
const features = app2.getGPUFeatureStatus();
|
|
625
|
+
return features.webgl.startsWith("enabled") ? WebGlStatus.WEBGL_ALLOWED : WebGlStatus.WEBGL_BLOCKED;
|
|
626
|
+
});
|
|
627
|
+
handle("chromeWebstore.install", async (event, id, silentInstall) => {
|
|
628
|
+
return Result.SUCCESS;
|
|
629
|
+
});
|
|
630
|
+
handle("chromeWebstore.isInIncognitoMode", async () => {
|
|
631
|
+
return false;
|
|
632
|
+
});
|
|
633
|
+
handle("chromeWebstore.isPendingCustodianApproval", async (event, id) => {
|
|
634
|
+
return false;
|
|
635
|
+
});
|
|
636
|
+
handle("chromeWebstore.setStoreLogin", async (event, login) => {
|
|
637
|
+
return true;
|
|
638
|
+
});
|
|
639
|
+
handle("chrome.runtime.getManifest", async () => {
|
|
640
|
+
return {};
|
|
641
|
+
});
|
|
642
|
+
handle("chrome.management.getAll", async (event) => {
|
|
643
|
+
const sessionExtensions = webStoreState.session.extensions || webStoreState.session;
|
|
644
|
+
const extensions = sessionExtensions.getAllExtensions();
|
|
645
|
+
return extensions.map(getExtensionInfo);
|
|
646
|
+
});
|
|
647
|
+
handle("chrome.management.setEnabled", async (event, id, enabled) => {
|
|
648
|
+
return true;
|
|
649
|
+
});
|
|
650
|
+
handle(
|
|
651
|
+
"chrome.management.uninstall",
|
|
652
|
+
async (event, id, options) => {
|
|
653
|
+
if (options?.showConfirmDialog) {
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
await uninstallExtension(id, webStoreState);
|
|
657
|
+
queueMicrotask(() => {
|
|
658
|
+
event.sender.send("chrome.management.onUninstalled", id);
|
|
659
|
+
});
|
|
660
|
+
return Result.SUCCESS;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
console.error(error);
|
|
663
|
+
return Result.UNKNOWN_ERROR;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// src/browser/updater.ts
|
|
670
|
+
import * as fs3 from "node:fs";
|
|
671
|
+
import * as path4 from "node:path";
|
|
672
|
+
import debug4 from "debug";
|
|
673
|
+
import { app as app3, powerMonitor, session as electronSession2 } from "electron";
|
|
674
|
+
var d4 = debug4("electron-chrome-web-store:updater");
|
|
675
|
+
var SYSTEM_IDLE_DURATION = 1 * 60 * 60 * 1e3;
|
|
676
|
+
var UPDATE_CHECK_INTERVAL = 5 * 60 * 60 * 1e3;
|
|
677
|
+
var MIN_UPDATE_INTERVAL = 3 * 60 * 60 * 1e3;
|
|
678
|
+
var lastUpdateCheck;
|
|
679
|
+
var ALLOWED_UPDATE_URLS = /* @__PURE__ */ new Set(["https://clients2.google.com/service/update2/crx"]);
|
|
680
|
+
var getSessionId = /* @__PURE__ */ (() => {
|
|
681
|
+
let sessionId;
|
|
682
|
+
return () => sessionId || (sessionId = crypto.randomUUID());
|
|
683
|
+
})();
|
|
684
|
+
var getOmahaPlatform = () => {
|
|
685
|
+
switch (process.platform) {
|
|
686
|
+
case "win32":
|
|
687
|
+
return "win";
|
|
688
|
+
case "darwin":
|
|
689
|
+
return "mac";
|
|
690
|
+
default:
|
|
691
|
+
return process.platform;
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
var getOmahaArch = () => {
|
|
695
|
+
switch (process.arch) {
|
|
696
|
+
case "ia32":
|
|
697
|
+
return "x86";
|
|
698
|
+
case "x64":
|
|
699
|
+
return "x64";
|
|
700
|
+
default:
|
|
701
|
+
return process.arch;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
function filterWebStoreExtension(extension) {
|
|
705
|
+
const manifest = extension.manifest;
|
|
706
|
+
if (!manifest) return false;
|
|
707
|
+
return manifest.key && manifest.update_url && ALLOWED_UPDATE_URLS.has(manifest.update_url);
|
|
708
|
+
}
|
|
709
|
+
async function fetchAvailableUpdates(extensions) {
|
|
710
|
+
if (extensions.length === 0) return [];
|
|
711
|
+
const extensionIds = extensions.map((extension) => extension.id);
|
|
712
|
+
const extensionMap = extensions.reduce(
|
|
713
|
+
(map, ext) => ({
|
|
714
|
+
...map,
|
|
715
|
+
[ext.id]: ext
|
|
716
|
+
}),
|
|
717
|
+
{}
|
|
718
|
+
);
|
|
719
|
+
const chromeVersion = getChromeVersion();
|
|
720
|
+
const url = "https://update.googleapis.com/service/update2/json";
|
|
721
|
+
const body = {
|
|
722
|
+
request: {
|
|
723
|
+
"@updater": "electron-chrome-web-store",
|
|
724
|
+
acceptformat: "crx3",
|
|
725
|
+
app: [
|
|
726
|
+
...extensions.map((extension) => ({
|
|
727
|
+
appid: extension.id,
|
|
728
|
+
updatecheck: {}
|
|
729
|
+
// API always reports 'noupdate' when version is set :thinking:
|
|
730
|
+
// version: extension.version,
|
|
731
|
+
}))
|
|
732
|
+
],
|
|
733
|
+
os: {
|
|
734
|
+
platform: getOmahaPlatform(),
|
|
735
|
+
arch: getOmahaArch()
|
|
736
|
+
},
|
|
737
|
+
prodversion: chromeVersion,
|
|
738
|
+
protocol: "3.1",
|
|
739
|
+
requestid: crypto.randomUUID(),
|
|
740
|
+
sessionid: getSessionId(),
|
|
741
|
+
testsource: process.env.NODE_ENV === "production" ? "" : "electron_dev"
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
const response = await fetch(url, {
|
|
745
|
+
method: "POST",
|
|
746
|
+
headers: {
|
|
747
|
+
"content-type": "application/json",
|
|
748
|
+
"X-Goog-Update-Interactivity": "bg",
|
|
749
|
+
"X-Goog-Update-AppId": extensionIds.join(","),
|
|
750
|
+
"X-Goog-Update-Updater": `chromiumcrx-${chromeVersion}`
|
|
751
|
+
},
|
|
752
|
+
body: JSON.stringify(body)
|
|
753
|
+
});
|
|
754
|
+
if (!response.ok) {
|
|
755
|
+
d4("update response not ok");
|
|
756
|
+
return [];
|
|
757
|
+
}
|
|
758
|
+
const text = await response.text();
|
|
759
|
+
const prefix = `)]}'
|
|
760
|
+
`;
|
|
761
|
+
if (!text.startsWith(prefix)) {
|
|
762
|
+
d4("unexpected update response: %s", text);
|
|
763
|
+
return [];
|
|
764
|
+
}
|
|
765
|
+
const json = text.substring(prefix.length);
|
|
766
|
+
const result = JSON.parse(json);
|
|
767
|
+
let updates;
|
|
768
|
+
try {
|
|
769
|
+
const apps = result?.response?.app || [];
|
|
770
|
+
updates = apps.filter((app5) => app5.updatecheck.status === "ok").map((app5) => {
|
|
771
|
+
const extensionId = app5.appid;
|
|
772
|
+
const extension = extensionMap[extensionId];
|
|
773
|
+
const manifest = app5.updatecheck.manifest;
|
|
774
|
+
const pkg = manifest.packages.package[0];
|
|
775
|
+
return {
|
|
776
|
+
extension,
|
|
777
|
+
id: extensionId,
|
|
778
|
+
version: manifest.version,
|
|
779
|
+
name: pkg.name,
|
|
780
|
+
url: app5.updatecheck.urls.url[0].codebase
|
|
781
|
+
};
|
|
782
|
+
}).filter((update) => {
|
|
783
|
+
const extension = extensionMap[update.id];
|
|
784
|
+
return compareVersions(extension.version, update.version) < 0;
|
|
785
|
+
});
|
|
786
|
+
} catch (error) {
|
|
787
|
+
console.error("Unable to read extension updates response", error);
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
return updates;
|
|
791
|
+
}
|
|
792
|
+
async function updateExtension(session, update) {
|
|
793
|
+
const sessionExtensions = session.extensions || session;
|
|
794
|
+
const extensionId = update.id;
|
|
795
|
+
const oldExtension = update.extension;
|
|
796
|
+
d4("updating %s %s -> %s", extensionId, oldExtension.version, update.version);
|
|
797
|
+
const oldVersionDirectoryName = path4.basename(oldExtension.path);
|
|
798
|
+
if (!oldVersionDirectoryName.startsWith(oldExtension.version)) {
|
|
799
|
+
console.error(
|
|
800
|
+
`updateExtension: extension ${extensionId} must conform to versioned directory names`,
|
|
801
|
+
{
|
|
802
|
+
oldPath: oldExtension.path
|
|
803
|
+
}
|
|
804
|
+
);
|
|
805
|
+
d4("skipping %s update due to invalid install path %s", extensionId, oldExtension.path);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const extensionsPath = path4.join(oldExtension.path, "..", "..");
|
|
809
|
+
const updatePath = await downloadExtensionFromURL(update.url, extensionsPath, extensionId);
|
|
810
|
+
d4("downloaded update %s@%s", extensionId, update.version);
|
|
811
|
+
if (sessionExtensions.getExtension(extensionId)) {
|
|
812
|
+
sessionExtensions.removeExtension(extensionId);
|
|
813
|
+
await sessionExtensions.loadExtension(updatePath);
|
|
814
|
+
d4("loaded update %s@%s", extensionId, update.version);
|
|
815
|
+
}
|
|
816
|
+
await fs3.promises.rm(oldExtension.path, { recursive: true, force: true });
|
|
817
|
+
}
|
|
818
|
+
async function checkForUpdates(session) {
|
|
819
|
+
const sessionExtensions = session.extensions || session;
|
|
820
|
+
const extensions = sessionExtensions.getAllExtensions().filter(filterWebStoreExtension);
|
|
821
|
+
d4("checking for updates: %s", extensions.map((ext) => `${ext.id}@${ext.version}`).join(","));
|
|
822
|
+
const updates = await fetchAvailableUpdates(extensions);
|
|
823
|
+
if (!updates || updates.length === 0) {
|
|
824
|
+
d4("no updates found");
|
|
825
|
+
return [];
|
|
826
|
+
}
|
|
827
|
+
return updates;
|
|
828
|
+
}
|
|
829
|
+
async function installUpdates(session, updates) {
|
|
830
|
+
d4("updating %d extension(s)", updates.length);
|
|
831
|
+
for (const update of updates) {
|
|
832
|
+
try {
|
|
833
|
+
await updateExtension(session, update);
|
|
834
|
+
} catch (error) {
|
|
835
|
+
console.error(`checkForUpdates: Error updating extension ${update.id}`);
|
|
836
|
+
console.error(error);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
async function updateExtensions(session = electronSession2.defaultSession) {
|
|
841
|
+
const updates = await checkForUpdates(session);
|
|
842
|
+
if (updates.length > 0) {
|
|
843
|
+
await installUpdates(session, updates);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
async function maybeCheckForUpdates(session) {
|
|
847
|
+
const idleState = powerMonitor.getSystemIdleState(SYSTEM_IDLE_DURATION);
|
|
848
|
+
if (idleState !== "active") {
|
|
849
|
+
d4('skipping update check while system is in "%s" idle state', idleState);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (lastUpdateCheck && Date.now() - lastUpdateCheck < MIN_UPDATE_INTERVAL) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
lastUpdateCheck = Date.now();
|
|
856
|
+
void updateExtensions(session);
|
|
857
|
+
}
|
|
858
|
+
async function initUpdater(state) {
|
|
859
|
+
const check = () => maybeCheckForUpdates(state.session);
|
|
860
|
+
switch (process.platform) {
|
|
861
|
+
case "darwin":
|
|
862
|
+
app3.on("did-become-active", check);
|
|
863
|
+
break;
|
|
864
|
+
case "win32":
|
|
865
|
+
case "linux":
|
|
866
|
+
app3.on("browser-window-focus", check);
|
|
867
|
+
break;
|
|
868
|
+
}
|
|
869
|
+
const updateIntervalId = setInterval(check, UPDATE_CHECK_INTERVAL);
|
|
870
|
+
check();
|
|
871
|
+
app3.on("before-quit", (event) => {
|
|
872
|
+
queueMicrotask(() => {
|
|
873
|
+
if (!event.defaultPrevented) {
|
|
874
|
+
d4("stopping update checks");
|
|
875
|
+
clearInterval(updateIntervalId);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// src/browser/index.ts
|
|
882
|
+
function resolvePreloadPath(modulePath) {
|
|
883
|
+
try {
|
|
884
|
+
return createRequire(import.meta.dirname).resolve("electron-chrome-web-store/preload");
|
|
885
|
+
} catch (error) {
|
|
886
|
+
if (process.env.NODE_ENV !== "production") {
|
|
887
|
+
console.error(error);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const preloadFilename = "chrome-web-store.preload.js";
|
|
891
|
+
if (modulePath) {
|
|
892
|
+
process.emitWarning(
|
|
893
|
+
'electron-chrome-web-store: "modulePath" is deprecated and will be removed in future versions.',
|
|
894
|
+
{ type: "DeprecationWarning" }
|
|
895
|
+
);
|
|
896
|
+
return path5.join(modulePath, "dist", preloadFilename);
|
|
897
|
+
}
|
|
898
|
+
return path5.join(import.meta.dirname, preloadFilename);
|
|
899
|
+
}
|
|
900
|
+
async function installChromeWebStore(opts = {}) {
|
|
901
|
+
const session = opts.session || electronSession3.defaultSession;
|
|
902
|
+
const extensionsPath = opts.extensionsPath || getDefaultExtensionsPath();
|
|
903
|
+
const loadExtensions = typeof opts.loadExtensions === "boolean" ? opts.loadExtensions : true;
|
|
904
|
+
const allowUnpackedExtensions = typeof opts.allowUnpackedExtensions === "boolean" ? opts.allowUnpackedExtensions : false;
|
|
905
|
+
const autoUpdate = typeof opts.autoUpdate === "boolean" ? opts.autoUpdate : true;
|
|
906
|
+
const minimumManifestVersion = typeof opts.minimumManifestVersion === "number" ? opts.minimumManifestVersion : 3;
|
|
907
|
+
const beforeInstall = typeof opts.beforeInstall === "function" ? opts.beforeInstall : void 0;
|
|
908
|
+
const webStoreState = {
|
|
909
|
+
session,
|
|
910
|
+
extensionsPath,
|
|
911
|
+
installing: /* @__PURE__ */ new Set(),
|
|
912
|
+
allowlist: opts.allowlist ? new Set(opts.allowlist) : void 0,
|
|
913
|
+
denylist: opts.denylist ? new Set(opts.denylist) : void 0,
|
|
914
|
+
minimumManifestVersion,
|
|
915
|
+
beforeInstall
|
|
916
|
+
};
|
|
917
|
+
const preloadPath = resolvePreloadPath(opts.modulePath);
|
|
918
|
+
if ("registerPreloadScript" in session) {
|
|
919
|
+
session.registerPreloadScript({
|
|
920
|
+
id: "electron-chrome-web-store",
|
|
921
|
+
type: "frame",
|
|
922
|
+
filePath: preloadPath
|
|
923
|
+
});
|
|
924
|
+
} else {
|
|
925
|
+
session.setPreloads([...session.getPreloads(), preloadPath]);
|
|
926
|
+
}
|
|
927
|
+
if (!existsSync(preloadPath)) {
|
|
928
|
+
console.error(
|
|
929
|
+
new Error(
|
|
930
|
+
`electron-chrome-web-store: Preload file not found at "${preloadPath}". See "Packaging the preload script" in the readme.`
|
|
931
|
+
)
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
registerWebStoreApi(webStoreState);
|
|
935
|
+
await app4.whenReady();
|
|
936
|
+
if (loadExtensions) {
|
|
937
|
+
await loadAllExtensions(session, extensionsPath, { allowUnpacked: allowUnpackedExtensions });
|
|
938
|
+
}
|
|
939
|
+
if (autoUpdate) {
|
|
940
|
+
void initUpdater(webStoreState);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
export {
|
|
944
|
+
downloadExtension,
|
|
945
|
+
installChromeWebStore,
|
|
946
|
+
installExtension,
|
|
947
|
+
loadAllExtensions,
|
|
948
|
+
uninstallExtension,
|
|
949
|
+
updateExtensions
|
|
950
|
+
};
|