Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-streets-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-core": patch
---

fix csp issue for mts realm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type { StartUIThreadCallbacks } from './startUIThread.js';
const existingScript = document.querySelector('script[nonce]') as
| HTMLScriptElement
| null;
const nonce = existingScript?.nonce || existingScript?.getAttribute('nonce');
const nonce = existingScript?.nonce || existingScript?.getAttribute('nonce')
|| '';

const {
prepareMainThreadAPIs,
Expand Down Expand Up @@ -57,7 +58,7 @@ async function createIFrameRealm(parent: Node): Promise<JSRealm> {
});
iframe.style.display = 'none';
iframe.srcdoc =
'<!DOCTYPE html><html><head><script>parent.postMessage("lynx:mtsready","*")</script></head><body style="display:none"></body></html>';
`<!DOCTYPE html><html><head><script nonce="${nonce}">parent.postMessage("lynx:mtsready","*")</script></head><body style="display:none"></body></html>`;
iframe.sandbox = 'allow-same-origin allow-scripts'; // Restrict capabilities for security
iframe.loading = 'eager';
parent.appendChild(iframe);
Expand All @@ -68,7 +69,7 @@ async function createIFrameRealm(parent: Node): Promise<JSRealm> {
script.fetchPriority = 'high';
script.defer = true;
script.async = false;
script.nonce = nonce || '';
script.nonce = nonce;
iframe.contentDocument!.head.appendChild(script);
return new Promise(async (resolve, reject) => {
script.onload = () => {
Expand All @@ -90,6 +91,7 @@ async function createIFrameRealm(parent: Node): Promise<JSRealm> {
xhr.send(null);
if (xhr.status === 200) {
const script = iframe.contentDocument!.createElement('script');
script.nonce = nonce;
script.textContent = xhr.responseText;
// @ts-expect-error
iframeWindow.module = { exports: undefined };
Expand Down
Loading