feat: 将发布预检移入内置浏览器

This commit is contained in:
2026-08-12 16:33:50 +08:00
parent be9bc84474
commit 926056a59b
16 changed files with 840 additions and 9 deletions

View File

@@ -67,6 +67,7 @@ function wrapWebContents(contents: WebContents): AgentBrowserWebContentsPort {
isDestroyed: () => contents.isDestroyed(),
isDevToolsOpened: () => contents.isDevToolsOpened(),
reload: () => contents.reload(),
executeJavaScript: (code) => contents.executeJavaScript(code),
denyWindowOpen: () => {
contents.setWindowOpenHandler(() => ({ action: 'deny' }));
},
@@ -151,6 +152,31 @@ export class ElectronAgentBrowserAdapter implements AgentBrowserAdapter {
await browserSession.clearCache();
}
restrictPartitionToOrigin(partition: string, origin: string): () => void {
const browserSession = session.fromPartition(partition);
const listener = (
details: Electron.OnBeforeRequestListenerDetails,
callback: (response: Electron.CallbackResponse) => void,
) => {
try {
const requestUrl = new URL(details.url);
const localDocumentScheme = requestUrl.protocol === 'about:'
|| requestUrl.protocol === 'data:'
|| requestUrl.protocol === 'blob:';
callback({
cancel: !localDocumentScheme
&& !(requestUrl.protocol === 'http:' && requestUrl.origin === origin),
});
} catch {
callback({ cancel: true });
}
};
browserSession.webRequest.onBeforeRequest({ urls: ['*://*/*'] }, listener);
return () => {
browserSession.webRequest.onBeforeRequest(null);
};
}
private requireNativeView(view: AgentBrowserViewPort): WebContentsView {
const nativeView = this.nativeViews.get(view);
if (!nativeView) throw new Error('Unknown Agent Browser view.');