开发者

Can you use jQuery POST in a Chrome extension?

开发者 https://www.devze.com 2023-01-20 07:29 出处:网络
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'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开发者_如何学JAVA anything useful with Chrome extensions.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消