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

How to run url in background of chrome extension

本文关键字:后台 运行 url 扩展 chrome      更新时间:2023-09-26

我正在尝试制作一个用于linkedin求职的chrome插件。要运行linkedinjavascriptapi,它需要一个domian,所以为了进行开发,我使用了localhost。现在,当点击chrome插件时,它会打开一个带有localhost url的新选项卡,并使用链接的API进行作业搜索。现在我希望url页面在插件的后台运行,以获得最新的作业更新。但是清单不会在后台加载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。请给我一些提示。

谢谢。

对于

 Uncaught Error: JavaScript API Domain is restricted to localhost

转到你在linkedin中创建的应用程序,在javascript选项sdk中,添加的url是localhost和另一个url。