Add importJS to the JS view client context (#1431)

This commit is contained in:
Jonatan Kłosko 2022-09-22 21:27:29 +02:00 committed by GitHub
parent 12f77daa68
commit 1ffdf8bf6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -26,7 +26,7 @@ import { sha256Base64 } from "../../lib/utils";
// (2): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox
// (3): https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts
const IFRAME_SHA256 = "Ogec/87xIEbz3xVctg9QCMqCPCTCf6vyL88bl41PR3I=";
const IFRAME_SHA256 = "vd7g1B8fLBFZH6C6KNpG4H8B0SQ/oIuqKaTW6jD053A=";
export function initializeIframeSource(iframe, iframePort, iframeUrl) {
const url = getIframeUrl(iframePort, iframeUrl);

View file

@ -78,11 +78,26 @@
});
},
importJS(url) {
return new Promise((resolve, reject) => {
const scriptEl = document.createElement("script");
scriptEl.addEventListener(
"load",
(event) => {
resolve();
},
{ once: true }
);
scriptEl.src = url;
document.head.appendChild(scriptEl);
});
},
handleSync(callback) {
state.syncHandler = callback;
},
selectSecret(callback, preselectName, options) {
selectSecret(callback, preselectName, options = {}) {
state.secretHandler = callback;
postMessage({ type: "selectSecret", preselectName, options });
},