如何在Google Chrome扩展程序中处理ERR_INSECURE_RESPONSE [英] How to handle ERR_INSECURE_RESPONSE in Google Chrome extension

查看:145
本文介绍了如何在Google Chrome扩展程序中处理ERR_INSECURE_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对我的URL进行简单的GET请求,并收到错误ERR_INSECURE_RESPONSE。这很好,因为证书是自签名的。但我有两个问题:

I'm doing simple GET request to my URL and I get the error "ERR_INSECURE_RESPONSE". THis is fine, as certificate is self-signed. But I have two questions regarding it:


  1. 有没有办法克服这个扩展?像在请求中设置一个标志或者像那样? (可能不太可能)

  2. 有没有办法处理这个错误(通知用户)?我检查了所有XMLHttpRequest字段,并且看不到任何可以指示此错误的内容。状态字段的值为0(零)。

有什么想法?

Any ideas?

推荐答案


  1. 不,扩展API不提供任何方法来修改SSL设置或行为。 chrome.webRequest.onErrorOccurred 事件以通知网络错误。 错误属性将包含网络错误代码。

  1. No, the extension API does not offer any method to modify SSL settings or behavior.
  2. You could use the chrome.webRequest.onErrorOccurred event to get notified of network errors. The error property will contain the network error code.

例如:

For example:

chrome.webRequest.onErrorOccurred.addListener(function(details) {
    if (details.error == 'net::ERR_INSECURE_RESPONSE') {
        console.log('Insecure request detected', details);
    }
}, {
    urls: ['*://*/*'],
    types: ['xmlhttprequest']
});
var x = new XMLHttpRequest;
x.open('get','https://example.com');
x.send();

如果仅用于测试,只需使用启动Chrome - ignore-certificate -errors 标志以允许使用自签名证书。这会影响同一浏览会话中的所有网站,因此我建议为此目的使用单独的配置文件目录,方法是追加 - user-data-dir = / tmp / temporaryprofiledirectory 到命令行参数。

If for testing only, just start Chrome with the --ignore-certificate-errors flag to allow self-signed certificates to be used. This affects all websites in the same browsing session, so I suggest to use a separate profile directory for this purpose, by appending --user-data-dir=/tmp/temporaryprofiledirectory to the command line arguments.

另一种避免错误的方法是获取有效的SSL证书。对于非商业目的,您可以在免费SSL证书 ://www.startssl.comrel =noreferrer> https://www.startssl.com 。

Another way to avoid the error in the first place is to get a valid SSL certificate. For non-commericial purposes, you can get a free SSL certificate at https://www.startssl.com.

这篇关于如何在Google Chrome扩展程序中处理ERR_INSECURE_RESPONSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆