Всем привет. Есть расширение под хром которое отлично работает, но в firefox показывает ошибку. Помогите решить проблему.
Uncaught TypeError: can't access property "addEventListener", chrome.extension.onMessage is undefined
background.js
var websocket,
ws = "link",
player = document.createElement("audio");
function connect(e) {
void 0 === websocket &&
(((websocket = new WebSocket(e)).onopen = function() {}),
(websocket.onmessage = function(e) {
var o = JSON.parse(e.data);
chrome.storage.local.get("title", function(e) {
if (e.title !== o.now_playing.song.title) {
if (!player.paused)
o.now_playing.song.title, o.now_playing.song.artist;
chrome.storage.local.set({
artwork: o.now_playing.song.art,
}),
chrome.storage.local.set({
title: o.now_playing.song.title,
}),
chrome.storage.local.set({
artist: o.now_playing.song.artist,
});
}
}),
"" === player.src && (player.src = o.station.listen_url),
chrome.runtime.sendMessage({
message: "radio_fetched",
data: o.now_playing.song,
});
}),
(websocket.onclose = function() {
websocket = void 0;
}));
}
function closeWebSocketConnection() {
(null == websocket && null == websocket) ||
(websocket.close(), (websocket = void 0));
}
chrome.extension.onMessage.addEventListener(function(e) {
"load" === e.action &&
(connect(ws),
chrome.runtime.sendMessage({
message: "player",
data: {
status: player.paused,
volume: player.volume,
},
})),
"play" === e.action &&
(player.paused ?
player.play() :
(player.pause(), closeWebSocketConnection())),
"volume" === e.action && (player.volume = e.data / 100);
});
popup.js
window.onload = function (e) {
chrome.storage.local.get('artwork', (e) => {
void 0 !== e.artwork && (document.getElementById('artwork').src = e.artwork);
}), chrome.storage.local.get('title', (e) => {
void 0 !== e.title && (document.getElementById('title').innerHTML = e.title);
}), chrome.storage.local.get('artist', (e) => {
void 0 !== e.artist && (document.getElementById('artist').innerHTML = e.artist);
}), chrome.extension.sendMessage({
action: 'load',
}), document.getElementById('play').addEventListener('click', () => {
e.preventDefault(), document.getElementById('play').classList.toggle('paused'), chrome.extension.sendMessage({
action: 'play',
});
}), document.getElementById('volume').addEventListener('change', function () {
chrome.extension.sendMessage({
action: 'volume',
data: this.value,
});
});
}, chrome.runtime.onMessage.addEventListener((e, t, n) => {
e.message === 'radio_fetched' && (document.getElementById('artwork').src = e.data.art, document.getElementById('title').innerHTML = e.data.title, document.getElementById('artist').innerHTML = e.data.artist), e.message === 'player' && (!1 === e.data.status && document.getElementById('play').classList.add('paused'), document.getElementById('volume').value = 30 * e.data.volume);
});