如何在Chrome扩展的后台运行url

问题描述:

我想为linkedin求职做一个chrome插件。要运行linkedin javascript api,它需要一个domian,所以为了开发,我使用了localhost。现在,当点击Chrome浏览器插件时,它会打开一个带有本地主机url的新选项卡,并使用链接的API执行作业搜索。 现在我想让url页面在插件的backgrowd中运行以获取最新的作业更新。但清单不会在后台加载url页面。如何在Chrome扩展的后台运行url

这里是我的manifest.json文件

{ 
    "manifest_version": 2, 
    "name": "Hunt Shire", 
    "version": "1.0", 
    "description": "This is a login plugin.", 
    "background":{   
     "page": "http://localhost:82/Plugin.html"   
    }, 
    "browser_action": 
    {   
     "defaul_title":"HuntShire", 
     "default_icon":"Hunt logo.png" 
    }, 
    "permissions": ["tabs", 
       "notifications", 
       "https://platform.linkedin.com/in.js" 
       ], 
    "web_accessible_resources":["Hunt Logo.png"] 

} 

反正运行它或任何其他的方式来运行特定域的参考背景脚本。

这是http://localhost:82/Plugin.html的一些脚本,它用链接的API提取数据。

api_key: xxxxxxxxxxx 
    onLoad: onLinkedInLoad 
    authorize: true 
    function onLinkedInLoad() { 
     IN.Event.on(IN, "auth", onLinkedInAuth); 
    }; 

    function onLinkedInAuth() { 
     IN.API.Profile("me").fields(["id", "firstName", "lastName", "emailAddress",  "positions:(company)", "following"]).result(displayProfiles); 
    }; 
    // some more query. 

,但如果我这样做在其他一些本地的HTML文件时,它给我一个错误 Uncaught Error: JavaScript API Domain is restricted to localhost。 请给我一些提示。

谢谢。

+0

取决于API,您可能可以使用Worker来使IO发生并将postMessage结果返回给您的应用程序。 – dandavis

+0

你能否给我解释一下,如何在后台运行它。 – shahwarcoder

+0

得到了一个会议,对不起。结账http://developer.chrome.com/apps/app_external.html大多数我会说的话...... – dandavis

对于

Uncaught Error: JavaScript API Domain is restricted to localhost 

转到您在LinkedIn和提出申请的JavaScript选项SDK添加网址为localhost和另一个URL的存在。