问题描述
情况:我正在撰写适用于任何网页的Chrome扩展程序。
问题问题:我不能将jQuery加载到Facebook中,我想了解发生了什么。
假设:Facebook拥有一些超先进的技术,以某种方式检测到:
- 当jQuery通过
表面上独立的 JSVM执行上下文中的chrome扩展加载时, Facebook megamind
以某种方式知道这种表面上独立的 JSVM执行
上下文,并阻止它。 -
(当我使用通过HTTPS而不是$ b $服务的Google CDN b jQuery一个没有方法2的工作,但对于
答案不够。)
我如何知道jQuery没有加载? / p>
我 在Chrome中启动控制台。当我这样做:
> jQuery
>> ReferenceError:没有定义jQuery。
> $('body')
>>错误:尝试获取元素body,但它不在页面上。
如何在Facebook中加载jQuery?
方法1(必需但失败):
通过manifest.json中的以下代码文件:
content_scripts:[
{
matches:[< all_urls> ],
js:[
javascript / jq / jquery-1.9.1.min.js,
javascript / jq / non-standard.js
],
all_frames:true //(或false,same failure)
}
]
方法2(工作,但不足):
通过此SO答案中描述的方法(),修改为允许正确的协议:
var jq = document.createElement('script');
jq.src =//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js;
document.getElementsByTagName('head')[0] .appendChild(jq);
jQuery.noConflict();
摘要
$ b假设1似乎不太可能,因为超越Web浏览器的单独执行上下文将是一个主要的安全漏洞(打破该沙盒),并且不太可能被批准。因此,我可能是偏执狂的,并且可以俯视到明显的,希望你们中的一个可以看到。附录(其他相关代码)
所有 non-standard.js :
$ .fn.in_groups_of = function(countPerGroup){
var groups = [],offset = 0,$ group;
while(($ group = this.slice(offset,(countPerGroup + offset)))。length){
groups.push($ group);
offset + = countPerGroup;
}
返回组;
};
更多的 manifest.json :
manifest_version:2,
权限:[
http:// * /,
https :// * /,
tabs,
storage,
unlimitedStorage
],
错了,是的。您需要查看正确的地方:
以前的截屏显示,Chrome开发人员工具的控制台选项卡在底部有两个下拉框,可用于更改开发人员工具控制台的执行环境。
左侧可用于更改框架上下文(顶部框架,因此iframe,...)和右侧侧面可用于更改脚本上下文(页面,内容脚本,...)。
Situation : I am writing a chrome extension that works on any page.
Problem Question : I can not load jQuery into Facebook and I would like to understand what is happening.
Hypotheses : Facebook possess some ultra advanced tech that somehow detects both :
- When jQuery is loaded via a chrome extension in anostensibly separate JSVM execution context, the Facebook megamindsomehow knows about this ostensibly separate JSVM executioncontext, and blocks it.
- (when I used the Google CDN which serves over HTTPS instead of thejQuery one which doesn't method 2 works, but is not sufficient foranswer).
DATA
How do I know jQuery is not loading?
I to bring up the console in Chrome. When I do :
> jQuery
>> ReferenceError : jQuery is not defined.
> $('body')
>> Error : Tried to get element "body" but it is not present on the page.
How do I attempt to load jQuery in facebook?
Method 1 (required but fails):
Via the following code in the manifest.json file :
"content_scripts" : [
{
"matches" : ["<all_urls>"],
"js" : [
"javascript/jq/jquery-1.9.1.min.js",
"javascript/jq/non-standard.js"
],
"all_frames": true // (or false, same failure)
}
]
Method 2 (works, but insufficent):
Via the method described in this SO answer (load jQuery into console), modified to permit the correct protocol :
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
Summary
Hypothesis 1 seems very unlikely, because over-riding the separate execution contexts of a web browser would be a major security vulnerability (break that sandbox), and not likely to be sanctioned. Therefore, I am probably being paranoid and overlooking the obvious, which hopefully one of you will see.
Appendix (other relevant code)
All of non-standard.js :
$.fn.in_groups_of = function( countPerGroup ) {
var groups = [], offset = 0, $group;
while ( ($group = this.slice( offset, (countPerGroup + offset) )).length ) {
groups.push( $group );
offset += countPerGroup;
}
return groups;
};
More of manifest.json :
"manifest_version" : 2,
"permissions" : [
"http://*/",
"https://*/",
"tabs",
"storage",
"unlimitedStorage"
],
Wrong, it does. You need to look at the correct place:
The previous screencast shows that the Console tab of the Chrome developer tools has two dropdown boxes at the bottom, which can be used to change the execution environment for the developer tools' console.
The left side can be used to change the frame context (top frame, so iframe, ...), and the right side can be used to change the script context (page, content script, ...).
这篇关于为什么jQuery不会在Facebook中加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!