NWJS - “拒绝在框架中显示...错误

发布于 2025-01-30 16:11:29 字数 877 浏览 3 评论 0原文

我试图在iframe中从本地网络上的设备显示网页。但是我得到:

“拒绝显示'http://192.168.1.252/'在框架中,因为它将'x-frame-options'设置为'Sameorigin'。 /(1)

我遵循了有关设置节点帧 https://docs.nwjs.io/en/latest/for%20users/advanced/security%20in%20nw.js/

我的清单文件:

{
  "name": "AppApp",
  "description": "AppApp",
  "version": "0.0.1",
  "icon": "icons/app.icns",
  "main": "html/main.html",
  "chromium-args": "--enable-logging=stderr --enable-spell-checking",
  "window": {
    "toolbar": false,
    "width": 800,
    "height": 500
  },
  "nodejs": true,
  "node-remote": "*://*"
}

html:

<iframe src="http://192.168.1.252/"></iframe>

iframe 我需要做更多的事情来绕过相同的原始政策?

I am attempting to display a webpage from a device on my local network in an iframe. However I get:

"Refused to display 'http://192.168.1.252/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.", source: chrome-error://chromewebdata/ (1)

I have followed the documentation regarding setting up node frames https://docs.nwjs.io/en/latest/For%20Users/Advanced/Security%20in%20NW.js/

My manifest file:

{
  "name": "AppApp",
  "description": "AppApp",
  "version": "0.0.1",
  "icon": "icons/app.icns",
  "main": "html/main.html",
  "chromium-args": "--enable-logging=stderr --enable-spell-checking",
  "window": {
    "toolbar": false,
    "width": 800,
    "height": 500
  },
  "nodejs": true,
  "node-remote": "*://*"
}

iframe HTML:

<iframe src="http://192.168.1.252/"></iframe>

Is there more that I need to do to bypass the same origin policy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时常饿 2025-02-06 16:11:29

这是一个错误,这里提供了解决方法:

https://github.com/ NWJS/nw.js/essess/7049

“ X-Frame-Options的解决方法应与NWFAKETOP属性一起使用。”

根据错误,如果x-frame-options:deny没有问题,则仅当问题存在时,只有x-frame-options:Sameorigin
nwfaketop必须使用解决方案。

(请注意,我观察到,在铬 - 弧中使用 - 可访问 - 网状安全性导致该页面无法正确加载,因此我将其删除。)

This is a bug, and a workaround is provided here:

https://github.com/nwjs/nw.js/issues/7049

"The X-Frame-Options workaround should be used in an iframe with the nwfaketop property."

According to the bug, if X-Frame-Options: Deny there isn't a problem, it is only if X-Frame-Options: sameorigin when the problem exists, and the
nwfaketop workaround must be used.

(Note, I observed that using --disable-web-security in chromium-args caused the page to not load properly, so I removed it.)

月依秋水 2025-02-06 16:11:29

不要 ---禁用 - web-security ,但请这样做:

步骤1:将下面的脚本保存为 background.js 和将此文件移至项目的文件夹...

// Removes x-frame-options and content-security-policy headers

chrome.webRequest.onHeadersReceived.addListener(function(info){

 var H=info.responseHeaders, N='';

  for(let i=H.length-1; i>=0; i--){

   N=H[i].name.toLowerCase();

   if((N.includes('x-frame-options'))||(N.includes('content-security-policy'))||(N.includes('report-'))){

    H.splice(i,1);

}} return {responseHeaders:H};},{urls:['<all_urls>'],types:['main_frame','sub_frame']},['blocking','responseHeaders','extraHeaders']);

2:在您的清单中。

 "background": {"scripts": ["background.js"],"persistent": true},

步骤 >在您的清单中

"permissions": ["<all_urls>","webRequest", .......

。重新加载令人讨厌的网站,最后笑! :)

Don't ---disable-web-security, but do this instead:

Step 1: Save the script below as background.js and move this file to your project's folder...

// Removes x-frame-options and content-security-policy headers

chrome.webRequest.onHeadersReceived.addListener(function(info){

 var H=info.responseHeaders, N='';

  for(let i=H.length-1; i>=0; i--){

   N=H[i].name.toLowerCase();

   if((N.includes('x-frame-options'))||(N.includes('content-security-policy'))||(N.includes('report-'))){

    H.splice(i,1);

}} return {responseHeaders:H};},{urls:['<all_urls>'],types:['main_frame','sub_frame']},['blocking','responseHeaders','extraHeaders']);

Step 2: In your manifest.json ensure you correctly accommodate this line...

 "background": {"scripts": ["background.js"],"persistent": true},

Step 3: In your manifest.json ensure you include "webRequest" among the other Chrome APIs etc...

"permissions": ["<all_urls>","webRequest", .......

Step 4: Now compile your app, reload the offending site and have the last laugh! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文