为什么jQuery不会在Facebook中加载? [英] Why will jQuery not load in Facebook?

查看:124
本文介绍了为什么jQuery不会在Facebook中加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:我正在撰写适用于任何网页的Chrome扩展程序。



问题问题:我不能将jQuery加载到Facebook中,我想了解发生了什么。



假设:Facebook拥有一些超先进的技术,以某种方式检测到:


  1. 当jQuery通过
    表面上独立的 JSVM执行上下文中的chrome扩展加载时, Facebook megamind
    以某种方式知道这种表面上独立的 JSVM执行
    上下文,并阻止它。

  2. jQuery通过script.src加载,并阻止它
    (当我使用通过HTTPS而不是$ b $服务的Google CDN b jQuery一个没有方法2的工作,但对于
    答案
    不够。)



我如何知道jQuery没有加载? / p>

j 在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答案中描述的方法(将jQuery加载到控制台),修改为允许正确的协议:

  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控制台似乎无法访问内容脚本的执行上下文。


错了,是的。您需要查看正确的地方:





以前的截屏显示,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 :

  1. When jQuery is loaded via a chrome extension in an ostensibly separate JSVM execution context, the Facebook megamind somehow knows about this ostensibly separate JSVM execution context, and blocks it.
  2. that jQuery is loaded via script.src and blocks it (when I used the Google CDN which serves over HTTPS instead of the jQuery one which doesn't method 2 works, but is not sufficient for answer).

DATA

How do I know jQuery is not loading?

I j 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"
                              ],

解决方案

The Chrome console does not appear to have access to the content script's execution context.

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中加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆