Electron - 从 BrowserWindow 的 loadUrl() 中检索 HTTP 响应标头

Electron - Retrieving HTTP response headers from the BrowserWindow#39;s loadUrl()(Electron - 从 BrowserWindow 的 loadUrl() 中检索 HTTP 响应标头)
本文介绍了Electron - 从 BrowserWindow 的 loadUrl() 中检索 HTTP 响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发一个托管在 SSO 环境中的电脑上的测试项目.我实际上指向的是托管在此环境中的服务器上的网页,我需要访问 cookie(刚刚得到它们)和请求的 http 标头.我研究了文档,似乎没有 loadUrl() 方法的回调函数,也没有我可以用来获取这些标头的选项.

I'm working on a test project hosted on a pc included in a SSO environment. I'm actually pointing to a webpage hosted on a server inside this environment and I need to access the cookies (just got them) and the http headers of the request. I studied the doc and it seems there isn't a callback function for the loadUrl() method nor an option I can use to get those headers.

参考链接

https://electronjs.org/docs/api/browser-window

loadUrl 有第二个可选参数,定义为 Electron.loadURLOption,但它似乎没有帮助

loadUrl has a second optional parameter that is defined as an Electron.loadURLOption but it doesn't seem to be helpful

interface LoadURLOptions {
    /**
     * An HTTP Referrer url.
     */
    httpReferrer?: (string) | (Referrer);
    /**
     * A user agent originating the request.
     */
    userAgent?: string;
    /**
     * Extra headers separated by "
"
     */
    extraHeaders?: string;
    postData?: (UploadRawData[]) | (UploadFile[]) | (UploadBlob[]);
    /**
     * Base url (with trailing path separator) for files to be loaded by the data url.
     * This is needed only if the specified url is a data url and needs to load other
     * files.
     */
    baseURLForDataURL?: string;
}

如果有任何帮助,我将不胜感激,谢谢

I'd appreciate any kind of help, thanks

推荐答案

您可以通过为 Web 上下文会话的 onCompletedonHeadersReceived 回调注册一个侦听器来实现此目的webRequest 属性,例如:

You can achieve this by registering a listener for the onCompleted or onHeadersReceived callback of the web context session's webRequest property, eg:

  const url = 'https://example.com/your/page';
  browserWindow.webContents.session.webRequest.onCompleted({ urls: [url] }, (details) => {
    // Access request headers via details.requestHeaders
    // Access response headers via details.responseHeaders
  });

  browserWindow.loadURL(url);

onHeadersReceived 有点棘手,因为它需要调用传递的回调才能继续页面加载过程.

The onHeadersReceived is a little trickier as it requires invoking the passed callback in order to continue the page loading process.

相关文档

这篇关于Electron - 从 BrowserWindow 的 loadUrl() 中检索 HTTP 响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)