Why will jQuery not load in Facebook?

后端 未结 3 502
失恋的感觉
失恋的感觉 2020-11-28 13:38

Situation : I am writing a chrome extension that works on any page.

Problem Question : I can not load jQuery into Facebook and I wo

3条回答
  •  时光说笑
    2020-11-28 14:07

    The Answer

    It seems my 'experimental method' was flawed. The assumption about the Chrome console's omniscience is incorrect. The Chrome console does not appear to have access to the content script's execution context. So although console was reporting that jQuery did not have access to the page, it actually did, from the content script's execution context.

    This was verified by adding a content script, test.js, to manifest.json :

    "content_scripts"         :   [
                                      {
                                        "matches"   : [""],
                                        "js"        : [
                                                        "javascript/jq/jquery-1.9.1.min.js",
                                                        "javascript/jq/non-standard.js",
                                                        "javascript/test.js" // <-- add
                                                      ],
    

    The content of test.js is :

        var jtest = $('body');
        alert(jtest);
        alert(jtest.text());
    

    Now whatever page I navigate to, the two alert boxes pop up as expected.

    It works!

提交回复
热议问题