H
H
Habr2020-08-11 19:52:14
JavaScript
Habr, 2020-08-11 19:52:14

Why don't functions from Background.js Chrome Extension work?

Good afternoon, there is an extension for chrome, it works on the VueJS framework - https://github.com/Kocal/vue-web-extension , according to the logic, the function from background.js should work
Manifest file

"background": {
    "persistent": true,
    "scripts": [
      "scripts/background.js"
    ]
  },

background.js
function pause() {
  chrome.browserAction.setIcon({path: '/images/icon_player.png'});
  .....
}
, called by the chrome.extension.getBackgroundPage().pause() method, but gives an error that there is no such function, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Habr, 2020-08-12
@RozmarinUS

Found a solution:
background.js

chrome.extension.onMessage.addListener((message) => {
  switch (message.type){
    case 'pause':
      return pause()
    case 'setStream':
      return setStream(message.data)
  }
});

From the popup:
chrome.extension.sendMessage({
type: "setStream",
data: {....}
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question