views:

21

answers:

1

I'm trying to get my Chrome extension working with the Google Calendar API. However, the way Google has set up the extension sandbox makes anything almost impossible.

I can't add the Calendar API using JavaScript because I've tried 200 different ways to include the http://www.google.com/jsapi library. Therefore, I want to try interact with the Calendar API with PHP. Is it even possible to do a POST from a Chrome extension in order to run my PHP file? If not, it's pretty much impossible to interact with any external API that doesn't have a downloadable library, isn't it? If that's the case, I don't see how you can make anything useful with Chrome extensions.

+2  A: 

I think you are still having difficulties because you don't completely understand the difference between content scripts and background pages.

Content scripts have certain limits. They can't:

  • Use chrome.* APIs (except for parts of chrome.extension)
  • Use variables or functions defined by their extension's pages
  • Use variables or functions defined by web pages or by other content scripts
  • Make cross-site XMLHttpRequests

Basically all they can is access DOM of a page where they were injected and communicate with background page (by sending requests).

Background page thankfully doesn't have any of those limits, only it can't access pages user is viewing. Good news is that background page can communicate with content scripts (again through requests).

As you can see background page and content scripts supplement each other. If you use both at the same time you have almost no limitations. All you need is correctly split your logic between those two.

As to your initial question - content scripts can't make cross domain requests, but background pages can. You can read more here.

serg
Serg, thanks for explaining the difference. I somewhat knew that already but your post helped make it a bit more clear. I wasn't aware that XMLHttpRequests existed. Do they allow the POSTing of JSON?
joshholat
@joshholat Yes, anything you want. You can include jquery (or your framework of choice) into bkgd page and use its ajax features instead of native XMLHttpRequest.
serg