WebView2解除CROS限制

FaniX 2023/6/16 发布 · 2023/6/16 更新 · 1212 次阅读

在Quicker的WebView2浏览器窗口中,可以通过自定义HTML和Javascript创建出一套方便易用的操作界面。

在默认配置下,WebView2不允许直接访问其他网站:

fetch('https://getquicker.net').then(x=>console.log(x.url))
Access to fetch at 'https://getquicker.net/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

可以在“附加的浏览器参数”中添加--disable-web-security解除CORS限制:

fetch('https://getquicker.net').then(x=>console.log(x.url))
https://getquicker.net/

使用这种方法,可以在一个WebView窗口中获取各种Web数据,如从API中获取数据、获取其他网页标题或内容等。

· {{comment.createTimeStr}}
{{reply.votePoints}}
回复   – {{reply.createTimeStr}}
回复 x
标签
目录
相关操作