【问题标题】:Loading iframe in google-chrome extension (Error: Protocols must match)在 google-chrome 扩展中加载 iframe(错误:协议必须匹配)
【发布时间】:2012-12-26 22:30:08
【问题描述】:

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"
  ]
}

background.js 中的代码:

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

document.body.appendChild(iframe)

我不断收到此错误:

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.

有没有办法解决这个问题?

【问题讨论】:

标签: javascript google-chrome-extension roblox


【解决方案1】:

您的代码中的问题是您的http://www.roblox.com/* 源不安全。 Chrome 错误消息的whitelist only secure resources部分指的是这个。您必须使用https://www.roblox.com/* 并声明

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

在清单文件中。我观察到您的域正在通过

拨打电话

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

http URL,未列入白名单。

进一步阅读的参考资料

【讨论】:

  • @Luaox:通过编辑您的问题发布您的相关代码,将检查它。
  • @Luaox:当我检查您的页面时,仍然有使用 https 协议而不是 https 进行的调用,这会导致错误。我猜你需要使用安全版本的域。
猜你喜欢
  • 2012-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
  • 2012-07-19
  • 1970-01-01
相关资源
最近更新 更多