Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电子-从浏览器窗口检索HTTP响应头';s loadUrl()_Javascript_Typescript_Electron - Fatal编程技术网

Javascript 电子-从浏览器窗口检索HTTP响应头';s loadUrl()

Javascript 电子-从浏览器窗口检索HTTP响应头';s loadUrl(),javascript,typescript,electron,Javascript,Typescript,Electron,我正在做一个测试项目,它托管在一台包含在SSO环境中的pc上。 实际上,我指向的是一个托管在这个环境中的服务器上的网页,我需要访问cookies(刚刚得到它们)和请求的http头。 我研究了文档,似乎没有针对loadUrl()方法的回调函数,也没有可以用来获取这些标题的选项 供参考的链接 loadUrl有第二个可选参数,该参数定义为Electron.loadURLOption,但似乎没有什么帮助 interface LoadURLOptions { /** * An HTTP

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

供参考的链接

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

interface LoadURLOptions {
    /**
     * An HTTP Referrer url.
     */
    httpReferrer?: (string) | (Referrer);
    /**
     * A user agent originating the request.
     */
    userAgent?: string;
    /**
     * Extra headers separated by "\n"
     */
    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;
}

我非常感谢您提供的任何帮助,谢谢

您可以通过注册web上下文会话的
webRequest
属性的
onCompleted
onHeadersReceived
回调的侦听器来实现这一点,例如:

  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有点棘手,因为它需要调用传递的回调以继续页面加载过程

相关的