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!
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!
Share Improve this question edited Nov 29, 2013 at 7:55 Niko asked Nov 29, 2013 at 7:14 NikoNiko 4,45810 gold badges51 silver badges91 bronze badges 8- Are you sure the above error is a result of this particular line of code ? It might be related to some other part of the code, so posting a little more "context" would be helpful. – gkalpak Commented Nov 29, 2013 at 7:18
- 1 Yes, this line of code is being typed directly in the javascript console. This is the only line unfortunately, so there is not more context for me to give =\ (I'm adding that detail to the question for future clarity) – Niko Commented Nov 29, 2013 at 7:53
-
The content scripts "live" in an isolated world. Thus the JS context of the web-page (which can be acdessed from the console) knows nothing about the JS context of the content script and vice versa. So the console knows nothing about your injecting
jQuery 2.0.3
. In order for it to work yoh should execute this line if code from a content script. – gkalpak Commented Nov 29, 2013 at 9:00 - While they are isolated, I know from personal experience that you can still access the content scripts from the console. It may just be the difference between a packed and unpacked extension (although I haven't tested if that's what makes a difference, but the extension is currently unpacked). Additionally I do know that it does work as I've been able to use JQuery in the console on other pages that do not ship with JQuery. Test it yourself if you don't believe me. – Niko Commented Nov 29, 2013 at 9:55
-
Unless you inject jQuery into the web-page's DOM (e.g. inserting a
<script>
I am pretty sure you cannot acces jQuery from the web-page's JS context. If you believe otherwise, I would be very interested in seeing your code :) – gkalpak Commented Nov 29, 2013 at 10:41
1 Answer
Reset to default 17You 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>
.