在带有扩展脚本的Chrome扩展程序中使用JS库

时间:2019-12-14 23:30:41

标签: javascript google-chrome-extension

我正在尝试在Chrome扩展程序中使用notie.js警报库。

Chrome扩展程序监视特定页面,该页面具有随机更新的特定编号。当数字的特定列发生更改时,我使用突变观察器将警报发送到屏幕。这对于默认通知可以很好地工作,但是不幸的是,它们不是非常可定制的。那就是我希望使用notie的地方。

我的主目录中有notie.js和notie.scss以及其他文件。

目前,我正在 Error in event handler: ReferenceError: notie is not defined

是否有更简单的方法来加载这两个文件并使用通知?

相关清单信息

"background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": ["*specific site url I'm watching for changes on here*"],
      "js": ["popup.js"]
    }
  ],
  "manifest_version": 2,
  "browser_action": {
    "default_popup": "popup.html"
  },
  "permissions": [
    "storage",
    "notifications",
    "tabs"
  ],

popup.js-消息发送到的地方

  chrome.runtime.sendMessage('insert-lib');

background.js

chrome.runtime.onMessage.addListener((message, {tab}) => {
  if (message === 'insert-lib') {
      chrome.tabs.executeScript(tab.index, {
          file: 'notie.js',
          file: 'notie.scss',
      });
      notie.alert({ type: 'success', text: 'Success!', time: 5 });
  }
});

0 个答案:

没有答案