Skip to content

Commit 64d988a

Browse files
committed
feat: 移除 csp 配置
1 parent 368c07a commit 64d988a

2 files changed

Lines changed: 6 additions & 30 deletions

File tree

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
],
2525
"security": {
26-
"csp": "default-src 'self'; style-src 'self' 'unsafe-inline' https:; script-src 'self' 'unsafe-inline' https:; img-src 'self' data: https: http:; font-src 'self' https:; connect-src 'self' ipc: https://ipc.localhost https:; frame-src 'self' blob: data:"
26+
"csp": null
2727
}
2828
},
2929
"bundle": {

src/components/markdown-preview.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -156,42 +156,18 @@ export class MarkdownPreview {
156156
return false;
157157
}
158158

159+
const blob = new Blob([code], { type: 'text/html' });
160+
const blobUrl = URL.createObjectURL(blob);
161+
159162
const iframe = document.createElement('iframe');
160163
iframe.className = 'html-preview-frame';
161164
iframe.sandbox = 'allow-scripts allow-same-origin';
162-
iframe.srcdoc = code;
165+
iframe.src = blobUrl;
163166
slot.appendChild(iframe);
164167

165-
// Catch errors from the iframe (works for same-origin srcdoc scripts)
166168
iframe.addEventListener('load', () => {
169+
URL.revokeObjectURL(blobUrl);
167170
iframe.classList.add('loaded');
168-
try {
169-
const win = iframe.contentWindow;
170-
if (!win) return;
171-
const errors = [];
172-
win.addEventListener('error', (ev) => {
173-
errors.push({
174-
message: ev.message || 'Unknown error',
175-
filename: ev.filename || '',
176-
lineno: ev.lineno || 0,
177-
colno: ev.colno || 0,
178-
stack: (ev.error && ev.error.stack) || '',
179-
});
180-
this._renderIframeErrors(iframe, errors);
181-
});
182-
win.addEventListener('unhandledrejection', (ev) => {
183-
errors.push({
184-
message: 'Unhandled rejection: ' + String(ev.reason),
185-
filename: '',
186-
lineno: 0,
187-
colno: 0,
188-
stack: (ev.reason && ev.reason.stack) || '',
189-
});
190-
this._renderIframeErrors(iframe, errors);
191-
});
192-
} catch {
193-
// Cross-origin iframe — can't attach error handlers
194-
}
195171
});
196172

197173
return true;

0 commit comments

Comments
 (0)