Firefox addon 在Firefox WebExtension中播放远程音频文件时出现CSP错误
我正在开发一个扩展,我需要从远程服务器播放音频,我有另一个服务器来获取其他信息 我在Firefox addon 在Firefox WebExtension中播放远程音频文件时出现CSP错误,firefox-addon,content-security-policy,firefox-addon-webextensions,Firefox Addon,Content Security Policy,Firefox Addon Webextensions,我正在开发一个扩展,我需要从远程服务器播放音频,我有另一个服务器来获取其他信息 我在manifest.json中添加了以下行: "content_security_policy": "default-src 'self' https://firstserver.com https://serverwithaudio.com;" 我也试过了 "content_security_policy": "default-src 'self' https://firstserver.com; me
manifest.json
中添加了以下行:
"content_security_policy": "default-src 'self' https://firstserver.com https://serverwithaudio.com;"
我也试过了
"content_security_policy": "default-src 'self' https://firstserver.com; media-src https://serverwithaudio.com;"
但它们都不起作用,我仍然会犯这样的错误:
内容安全策略:页面设置阻止加载
资源在
(“默认src”)
是否可以播放来自两个不同来源的远程音频,或者我的manifest.json中遗漏了什么内容?我解决了这个问题
首先,如果您将内容安全策略
放入清单.json
中,您将无法在Mozilla扩展目录中提交它
其次,我将音频文件移动到了获取信息的同一台服务器上。然后播放背景脚本中的音频
当我单击内容脚本上的按钮时,我会向后台脚本发送一条带有音频url的消息:
let audioUrl = "https://example.com/media/audio.mp3";
chrome.runtime.sendMessage({audio: audioUrl});
在背景脚本中:
chrome.runtime.onMessage.addListener(function(req, sender, sendResponse){
if (req.audio) {
(new Audio(req.audio)).play();
}
return true;
});
请记住,您仍然需要在许可指令中提到您的主机
"permissions": [
"*://example.com/"
]