在Safari扩展注入脚本跨起源AJAX调用起源、脚本、Safari、AJAX

2023-09-10 17:41:31 作者:三分醒七分醉

我试图找出正确的配置,在Safari扩展注入脚本跨起源AJAX调用。

I'm trying to figure out right configuration for cross origin AJAX call in Safari extension injected script.

我在扩展生成器的配置:

My configuration in Extension Builder:

在推广网站访问:所有 在包括安全页数:真正的 白名单: - 黑名单: -

我的目标是要达到这样的铬合金权限:http://mysite.com/*,并能够从Web服务拉动用户配置

My goal is to get something like Chromes "permissions": "http://mysite.com/*", and be able to pull user configuration from web service.

请注意:JSONP下降的警告,所以我会preFER,以避免它。

note: JSONP drops warning, so I would prefer to avoid it.

推荐答案

任何运气呢?我有同样的问题。同样的设置工作正常的Chrome扩展,但试图做到这一点在Safari浏览器插件,当触及接入控逆变 - 允许 - 产地。

Any luck with this? I'm having the same problems. Same setup works fine in the Chrome extension, but hitting Access-Contol-Allow-Origin when trying to do it in Safari Extension.

固定 - 更新: 嘿,我想通了什么问题。因此,它看起来像你需要通过后台页面做跨域Ajax。我到底是什么了做的是确定所有我需要在注入脚本的要求,那么消息传递请求后台页面。背景页侦听来自注入的脚本消息,使得适当Ajax调用,然后通过一个消息到注入脚本发送的结果。注入的脚本,然后侦听来自后台页面的消息,一旦获得消息(S)与阿贾克斯的结果,它需要在正在被浏览的网页进行相应的操作。

FIXED - UPDATE: Hey, I figured out what the problem is. So, it looks like you need to do the cross-domain ajax via the background page. What I end up doing is determining all the requests I need to make in the injected script, then message pass the requests to the background page. The background page listens for messages from the injected script, makes the appropriate ajax calls, and then sends the results via a message to the injected script. The injected script is then listening for messages from the background page, once it gets the message(s) with the ajax results, it takes the appropriate action in the page that's being viewed.