1

I'm taking a stab at building my first Chrome Extension. Basically what I want to do is, click the extension icon, grab the page title, URL, and selected content from the current page, open a new window, and pass that data into this new window.

I've got it most of the way there, but I'm having trouble figuring out how to execute code after the window is fully loaded.

Here is a gist with all of the files of the extension.

I want to execute the contentscript.js and insertdata.js code after the window has loaded, and to use jQuery on the pages (if it exists). For some reason, even if I set an interval to continuously check if $ was a function, it never was. I guess I don't understand why I can't access the JS functions available on the page.

Also, all of this code seems kind of convoluted, so I'm wondering if there is some better way to accomplish this. Thanks in advance for any help.

Trevor Davis
  • 411
  • 3
  • 8
  • Does using `"run_at": "document_end",` in `content_scripts` in your manifest not help? http://developer.chrome.com/extensions/content_scripts.html Scroll down to "run_at" for more information. – Rhyono Aug 30 '12 at 04:09
  • By default, content scripts are executed around/after the occurrence of the `load` event. That being said, you can *never* access the jQuery object directly. See [Chrome extension code vs Content scripts vs Injected scripts](http://stackoverflow.com/questions/9915311/chrome-extension-code-vs-content-scripts-vs-injected-scripts/9916089#9916089) for a detailed explanation. – Rob W Aug 30 '12 at 12:15
  • @RobW - Ahh ok, that answers my main question then. Thanks! – Trevor Davis Aug 30 '12 at 13:12
  • @RobW - Ok, one more question then. If I tweak my contentscript.js to inject jQuery into the page, why is $ still undefined when I do a console.log? I see it being injected into the page: https://gist.github.com/1b0a6b0becc01869aab2 – Trevor Davis Aug 30 '12 at 13:51
  • @TrevorDavis Because the `onload` event handler runs in the context of a Content script. If all you want to do is to use jQuery, just [include jQuery as a content script](http://stackoverflow.com/questions/3209790/jquery-in-google-chrome-content-script). – Rob W Aug 30 '12 at 14:14

1 Answers1

0

Take a look to the 'Test Screenshot Extension': http://developer.chrome.com/trunk/extensions/samples.html

This extension is for screenshot, but it wait if it have the screenshot then it open that information in a new tab page.

user1731468
  • 864
  • 2
  • 9
  • 30