javascript - 是否可以在内容脚本中使用 Chrome API?
问题描述
我目前正在尝试通过内容脚本下载文件。然而,它似乎什么也没做。我还尝试向我的后台脚本发送消息,然后从后台文件下载它,但是似乎没有收到任何消息。
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if(message == "handle_all") {
let is_playing = document.getElementsByClassName("playControl")[0].innerHTML == "Pause current";
let volume = document.getElementsByClassName("volume__sliderWrapper")[0].getAttribute('aria-valuenow');
SC.initialize({
client_id: 'censored',
});
if(is_playing) {
SC.resolve('https://soundcloud.com/moow-beatmaker/it-wasnt-me').then(function(track) {
chrome.downloads.download({
url: "track.download_url + '?client_id=censored'",
});
});
}
}
});
什么都没发生。没有下载,什么都没有。当我自己访问下载页面时,我收到错误代码 406“不可接受”。
这是无法在内容脚本中使用 Chrome API 的问题,还是我从中下载文件的 API 有问题?
解决方案
推荐阅读
- javascript - 如何从已解决的获取请求中消费未来?
- php - MYSQL 复制数组值
- r - 在转到 R 中的下一行之前,如何使每一行的函数返回值?
- android - RecyclerView Textwatcher 值不起作用
- python - 使用类实例中的索引引用时调用什么方法?
- swift - 取消嵌套的 Promise 会发出警告:“待处理的承诺已解除”
- jq - jq,如果它是一个带有解析 JSON 表示的字符串,则重新分配字段
- python - AttributeError:“str”对象没有带有 StringVar 的属性“set”
- user-interface - Flutter,如何将 UI 放到按钮上?
- fpga - Cyclone 10 FPGA的被动并行加载什么样的文件?