在google-chrome扩展中加载iframe(错误:协议必须匹配) [英] Loading iframe in google-chrome extension (Error: Protocols must match)
问题描述
在manifest.json中的代码:
{
name:Test,
version:1.0,
manifest_version:2,
description:Test,
browser_action:{
default_icon:图标。 png,
default_popup:popup.html
},
权限:[
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
文档。
不安全的JavaScript尝试访问带有URL扩展名的框架://dbekkpdpdheclekbpajgigjdlpleolgd/_generated_background_page.html从URL http://www.roblox.com/User.aspx?ID=1。请求访问的帧具有'http'协议,被访问的帧具有'chrome-extension'协议。协议必须匹配。
有没有办法解决这个问题?
解决方案您的代码中的问题是您的
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 usehttps://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
这篇关于在google-chrome扩展中加载iframe(错误:协议必须匹配)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!