Google Chrome: JQuery content script on Facebook

狂风中的少年 提交于 2019-12-29 07:06:07

问题


I am using Google Chrome and I'm writing a browser extension. I'm trying to inject JQuery 2.0.3 into facebook as a context script. Just to see if I could, I'm trying to grab the text area on the message page. I'm typing this line directly into the Javascript console:

$('textarea[name="message_body"]');

Instead of getting a JQuery object I'm getting this error:

Error: <![EX[["Tried to get element with id of \"%s\" but it is not present on the page.","undefined"]]]>

Does facebook have anti-jquery measures or is there something else happening that I'm doing wrong? As usual, thanks all in advance!


回答1:


You are accessing a $() function defined in the Facebook page, which has nothing to do with jQuery. To access the execution context of you content scripts from the javascript console, you need to select it from the drop down box located at the bottom of the window:

Instead of <page context>, you have to select chrome-extension://<your extension id>.



来源:https://stackoverflow.com/questions/20280255/google-chrome-jquery-content-script-on-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!