mirror of
https://github.com/CryptKeeperZK/Docs.git
synced 2026-01-07 20:03:57 -05:00
1014 B
1014 B
🔌 Connect to extension
Connect to extension
Use zkpr.connect to access the extension.
Initialize the zkpr.connect function, which returns a promise that resolves to the client object.
Once you have the client object, you can use it to make RPC calls to the extension.
@src/contentscripts/injected.ts
async function connect() {
let result
try {
const approved = await tryInject(window.location.origin)
if (approved) {
await addHost(window.location.origin)
result = client
}
} catch (err) {
// eslint-disable-next-line no-console
console.log('Err: ', err)
result = null
}
await post({ method: RPCAction.CLOSE_POPUP })
return result
}
declare global {
interface Window {
zkpr: {
connect: () => any
}
}
}// Some code