javascript - Puppeteer:“您要提交的信息不安全”
问题描述
使用 Puppeteer 提交表单后,我收到以下消息:
Location
该消息是由不安全的响应标头(HTTP 资源而不是 HTTPS)触发的。
为了解决这个问题,我一直在考虑两种选择:
- 避免此消息。如何避免?
- 拦截 HTTP 请求并将其修改为 HTTPS 请求。怎么做?
关于选项 2,我尝试了以下方法:
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', request => {
console.log('Request', request.url());
if (request.url().startsWith('http://')) {
console.log('HTTP Request')
let secureUrl = request.url().replace('http://', 'https://');
// TO-DO: set here the 'secureUrl' to the request.
}
request.continue();
});
解决方案
此页面似乎在 puppeteer 请求事件之前触发,因此无法修改,解决方法可能只是:
if (await page.$('.insecure-form') !== null) {
await page.click('#proceed-button')
await page.waitForNavigation({ waitUntil: 'networkidle0' })
}
推荐阅读
- php - 如何启动 Laravel 应用程序?
- python - Django 3:不确定为什么我会收到 CSRF 错误
- python - python中变量前的单星号和双星号有什么区别?
- image - 引导 4 类使导航品牌形象仅出现在中及之后
- sql-server - 生成 2 个日期范围之间的周范围
- python - sp_execute_external_script 返回数据集输出的 Python 脚本
- c++ - io_service::run() 在迁移到 boost 1.72 后没有完成
- r - 在 R 中为动态执行的函数设置一个值
- python-3.x - pandas.Series 如何返回输入日期之前最接近日期的索引
- javascript - Discord.js,消息未定义错误,有什么解决方案吗?