1

I'm trying my hand at a Chrome extension. On a "regular" page, I can seem to fetch whatever that is I need ( ('.myclass'), for instance).

On an https page, it returns null. I'm loading jQuery from my extensions folder as mentioned here. I thought I was doing something wrong in my extensions code, but running $(this) on a "regular" page ( such as SO homepage) returns all properties/methods, but on a a https page - this returns null.

Is jQuery not being injected into the page?

FTR: The https page I'm working on is Google Adsense. Below is the portion on my manifest.json:

 "background_page": "ga.html",
   "content_scripts": [
   {
     "matches": ["https://www.google.com/adsense/*"],
     "js": ["jquery.js", "cnt.js"]
   }
   ],
  "permissions": ["https://www.google.com/adsense/*"]

To add from comments: My cnt.js contains just this:

$(document).ready(function(){
 alert('Hi!');
 });

Strange thing is that the alert pops up before the page load is complete on Adsense page, which for other pages, it pops up after the load is complete

Community
  • 1
  • 1
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
  • Extensions don't work on Google pages as far as I know... Or maybe it's just they don't work within the extension gallery pages... Either way you might want to check. – Endophage Mar 14 '11 at 16:03
  • @Endophage they don't work on Extension gallery pages, IIRC – Sathyajith Bhat Mar 14 '11 at 16:05
  • look at the src of your jquery file on your ` – Val Mar 14 '11 at 16:06
  • I don't have adsense account but I tried it on `https://www.google.com/analytics/` and it worked. – serg Mar 14 '11 at 17:52
  • @Serg - no dice, even on Analytics it doesn't work – Sathyajith Bhat Mar 17 '11 at 14:52

1 Answers1

0

Can you try and inject the page at document_end? Perhaps there is a conflict in adsense with jQuery? Can you check in the console and see if there are any $ mapped already.

For now, try adding the document_end:

 "background_page": "ga.html",
 "content_scripts": [{
   "matches": ["https://www.google.com/adsense/*"],
   "js": ["jquery.js", "cnt.js"],
   "run_at": "document_end"
 }],
"permissions": ["https://www.google.com/adsense/*"]
Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
  • thanks, but it does not work :( How can I verify `any $ mapped already.` ? – Sathyajith Bhat Mar 17 '11 at 14:51
  • You type "$" in the adsense web inspector. In cnt.js, just put alert('ping'), reload your extension, and see if a alert will be shown when you visit https://www.google.com/adsense/* – Mohamed Mansour Mar 17 '11 at 20:15
  • Thanks. I noticed that the alert was popping up before Adsense page loads, however for other sites, the alert pops up after the page loads. The alert was added to my cnt.js, which as of now contains `$(document).ready(function() { alert('Hi!');});` – Sathyajith Bhat Mar 19 '11 at 15:33