-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpreload.ts
More file actions
40 lines (35 loc) · 1.67 KB
/
preload.ts
File metadata and controls
40 lines (35 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ipcRenderer } from "electron";
process.once('loaded', () => {
console.log(process.env);
if (process.platform === 'win32' && !(process.env && process.env['FIDO2_CLIENT_FORCE_PRELOAD'] === 'TRUE')) return;
if (!navigator.credentials) return;
const { get, create } = navigator.credentials;
Object.assign(navigator.credentials, {
create: async (options?: CredentialCreationOptions) => {
/**
* Only handle WebAuthn options, other options should fallback built-in handler
*/
if (typeof options?.publicKey !== 'object') return create(options);
/**
* Invoke create request to main process.
*/
const x = await ipcRenderer.invoke('navigator.credentials.create', options).catch(() => {
throw new DOMException('The operation either timed out or was not allowed. See: https://www.w3.org/TR/webauthn-2/#sctn-privacy-considerations-client.');
});
return x;
},
get: async (options?: CredentialRequestOptions) => {
/**
* Only handle WebAuthn options, other options should fallback built-in handler
*/
if (typeof options?.publicKey !== 'object') return get(options);
/**
* Invoke create request to main process.
*/
const x = await ipcRenderer.invoke('navigator.credentials.get', options).catch(() => {
throw new DOMException('The operation either timed out or was not allowed. See: https://www.w3.org/TR/webauthn-2/#sctn-privacy-considerations-client.');
});
return x;
}
});
});