Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 我的网站位于;“权限”;,但要不断地得到;起源铬-extension://abc 访问控制允许源站不允许;_Google Chrome_Google Chrome Extension_Xmlhttprequest - Fatal编程技术网

Google chrome 我的网站位于;“权限”;,但要不断地得到;起源铬-extension://abc 访问控制允许源站不允许;

Google chrome 我的网站位于;“权限”;,但要不断地得到;起源铬-extension://abc 访问控制允许源站不允许;,google-chrome,google-chrome-extension,xmlhttprequest,Google Chrome,Google Chrome Extension,Xmlhttprequest,我已经在一个旧的扩展的基础上开始了新的扩展,我以前写过这个扩展,现在可以正常工作了。对于Google Chrome extensions,执行xhr的方案非常正常:内容脚本调用Chrome.extension.sendRequest(数据,回调),实际的跨站点请求在backround.html中完成 此外,我还确保将请求的站点添加到manifest.json的“permissions”部分 然而,background.html的控制台显示:“…Origin chrome”-extension:/

我已经在一个旧的扩展的基础上开始了新的扩展,我以前写过这个扩展,现在可以正常工作了。对于Google Chrome extensions,执行xhr的方案非常正常:内容脚本调用Chrome.extension.sendRequest(数据,回调),实际的跨站点请求在backround.html中完成

此外,我还确保将请求的站点添加到manifest.json的“permissions”部分

然而,background.html的控制台显示:“…Origin chrome”-extension://.. 访问控制允许源不允许。”

问题如下:除了在“权限”中没有目标域(我甚至在这里也尝试过),还有什么可能导致此错误


以下是一些重要的代码片段:

manifest.json:

{
    "name": "Register quote",
    "version": "0.0.2",
    "permissions": [ "<all_urls>" ],
    "background_page" : "background.html",
    "content_scripts": [
        {
            "matches": [
                "http://somedomain.com/*"
            ],
            "css": ["register_quote.css"],
            "js": ["jquery-1.3.2.min.js", "register_quote.user.js"]
        }
    ]
}
// here's the final call, how it's prepared by the content script after all:
chrome.extension.sendRequest({
    'action': 'sendAjaxRequest',
    'url': "http://somedomain.com/the_script.php"
    'dataStr': "is_chrome=Y&ticketid=123123123&user=Vladimir+Mityukov&action=get_quoteids"
}, arg_callback);

注意:忘了提及,backround.html的控制台中还有以下错误:

 Error in event handler for 'undefined': TypeError: Cannot read property 'length' of undefined
    at setupPageActionEvents (chrome/ExtensionProcessBindings:424:36)
    at chrome/ExtensionProcessBindings:1021:5
    at [object Object].dispatch (chrome/EventBindings:182:28)
    at Object.<anonymous> (chrome/EventBindings:237:25)
“未定义”的事件处理程序中出现错误:TypeError:无法读取未定义的属性“length” 在setupPageActionEvents(chrome/ExtensionProcessBindings:424:36) 在chrome/ExtensionProcessBindings:1021:5 在[object object].dispatch(chrome/EventBindings:182:28) 反对。(chrome/EventBindings:237:25)
我不知道这条消息是什么意思,我的代码的哪一部分会导致它。。这里提到的脚本不是我的。

这可能是由于
的一些奇怪之处造成的。”


另一方面,现在允许内容脚本进行跨源XHR调用:

版本说明:从Chrome13开始,内容脚本可以向与扩展其余部分相同的服务器发出跨源请求。在Chrome13之前,内容脚本不能直接发出请求;相反,它必须向其父扩展发送一条消息,要求该扩展发出跨源请求。”


在这种情况下,您需要添加
http://somedomain.com/
添加到清单中的权限列表。

上面的答案是错误的,我想向未来的读者澄清一下,因为我也有同样的问题

这是因为服务器的访问控制允许源不允许Chrome://extension 起源类型

无论何时发送到服务器,都会有一个源标题。在Chrome extensions中,这是“Chrome extension/:blarg-blarg-blarg”

很多服务器都有“*”的“Access Control Allow Origin”,因此在大多数情况下,api调用都会通过

但是,如果Access Control Allow Origin需要一个http地址或某个域,那么就没有多少方法可以让它工作


它在内容脚本上工作,因为您有url本身的来源,即“http://blarg blarg blarg“

乍一看,我似乎无法找到问题所在,但您知道可以直接从内容脚本发出XHR吗?您应该使用“暂停未捕获异常”启动调试器“已启用以查找导致
无法读取属性'length'错误的代码。>但是您知道现在可以直接从内容脚本发出XHR吗?”?耶,它现在可以在没有background.html代理的情况下工作了!在我尝试之前,有规律的模式,所以,这不是原因。然而,使用contentscript本身内部的xhr调用就成功了!
"permissions": [ "http://somedomain.com/*" ]