From 8d6bf67e5b034cfaacfecdd9a341f81303f98068 Mon Sep 17 00:00:00 2001 From: J-fla Date: Fri, 31 Jul 2026 17:33:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0webContents.cookies.g?= =?UTF-8?q?et=E6=96=B9=E6=B3=95=E5=AE=9A=E4=B9=89,=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=AF=BB=E5=8F=96HttpOnly=E7=AD=89=E7=A7=81=E6=9C=89Cookie?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbw.d.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zbw.d.ts b/zbw.d.ts index 2f84260..18d6c68 100644 --- a/zbw.d.ts +++ b/zbw.d.ts @@ -56,6 +56,41 @@ declare namespace BrowserWindow { closeDevTools: () => void copy: () => void copyImageAt: (x: number, y: number) => void + /** + * 读取当前 webContents 关联 session 的 Cookie。 + * + * 通过主进程 `session.fromPartition(partition).cookies.get()` 实现, + * 可读取 `document.cookie` 无法获取的 HttpOnly Cookie(如登录态 sessionid)。 + * + * @example + * // 读取指定 URL 的所有 cookie(含 HttpOnly) + * const cookies = await win.webContents.cookies.get({ url: 'https://example.com' }) + * const sessionId = cookies.find(c => c.name === 'sessionid')?.value + * + * @param filter 可选过滤条件,与 Electron Cookies.get filter 一致 + */ + cookies: { + get: (filter?: { + url?: string + name?: string + domain?: string + path?: string + secure?: boolean + session?: boolean + httpOnly?: boolean + }) => Promise< + Array<{ + name: string + value: string + domain?: string + path?: string + secure?: boolean + httpOnly?: boolean + expirationDate?: number + sameSite?: 'unspecified' | 'no_restriction' | 'lax' | 'strict' + }> + > + } cut: () => void /** * @deprecated