且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在google-chrome扩展中加载iframe(错误:协议必须匹配)

更新时间:2023-12-05 20:35:46

您的代码中的问题是您的 http://www.roblox.com/* 来源不安全。 Chrome错误消息中的白名单仅限安全资源部分引用了此内容。您必须使用 https://www.roblox.com/* 并声明


content_security_policy:script-src https://roblox.com 'self'; object-src'self' 清单文件中的

。我观察到您的域名已通过


/ AdSense内容拨打电话。 aspx?v = 2& slot = Roblox_User_Top_728x90& format = banner& v = 2rel =nofollow> http://www.roblox.com/Ads/IFrameAdContent.aspx?v=2&slot=Roblox_User_Top_728x90&format= banner& v = 2 。

http 网址是不是白名单。



进一步阅读的参考




Code in manifest.json:

{
  "name": "Test",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Test",
  "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "popup.html"
  },
  "permissions": [
      "notifications",
      "https://www.roblox.com"
  ],
  "background": { "scripts": ["background.js"] },
  "content_security_policy": "script-src https://www.roblox.com 'self' ; object-src 'self'",
  "web_accessible_resources": [
    "icon.png"
  ]
}

Code in background.js:

var iframe = document.createElement("iframe")
iframe.src = "http://www.roblox.com/User.aspx?ID=1"

document.body.appendChild(iframe)

I keep getting this error:

Unsafe JavaScript attempt to access frame with URL chrome-extension://dbekkpdpdheclekbpajgigjdlpleolgd/_generated_background_page.html from frame with URL http://www.roblox.com/User.aspx?ID=1. The frame requesting access has a protocol of 'http', the frame being accessed has a protocol of 'chrome-extension'. Protocols must match.

Is there anyway to fix this?

Problem in your code is your http://www.roblox.com/* source is not secure. The whitelist only secure resources part of the Chrome error message refers to this. You have to use https://www.roblox.com/* and declare

"content_security_policy": "script-src https://roblox.com 'self' ; object-src 'self'"

in manifest file. I observed your domain has is making calls through

http://www.roblox.com/Ads/IFrameAdContent.aspx?v=2&slot=Roblox_User_Top_728x90&format=banner&v=2.

http URL, which is not white listed.

References for further reading