我正在使用MV 3创建一个chrome扩展,它会在文档正文中插入一个下载按钮。我尝试使用该下载按钮下载另一个URL上的示例PDF,但无法执行此操作。当我单击该按钮时,Chrome只会在当前选项卡中打开PDF。我需要将其像普通文件一样下载到计算机。我在清单中拥有下载权限,但我不确定我做错了什么。任何帮助将不胜感激!
这是我的contentScript.JS文件中存储下载按钮的位置。
function createModal() {
var auroraModal = document.createElement('div');
auroraModal.className = '_aurora__modal';
auroraModal.id = '_aurora__modal';
var downloadLink = document.createElement('a');
downloadLink.download = "Example.pdf";
downloadLink.href = "https://www.africau.edu/images/default/sample.pdf";
downloadLink.innerHTML = 'Download';
auroraModal.innerHTML = '<p>Woo-hoo <strong>'+dataFromPromise+'</strong>! Your custom PDF is ready!</p>';
auroraModal.appendChild(downloadLink)
document.body.appendChild(auroraModal)
}
这是我的载货单
{
"name": "Aurora Extension",
"manifest_version": 3,
"description": "Aurora extension attempt with FB9 and MV3",
"permissions": ["storage", "tabs", "downloads"],
"host_permissions": ["https://*.stackoverflow.com/*"],
"background": { "service_worker": "background/index.js" },
"content_scripts": [
{
"js": ["content/index.js"],
"css": ["content/coupon.css"],
"matches": ["https://*.stackoverflow.com/*"]
}
],
"action": { "default_popup": "pages/popup/index.html" }
}
2条答案
按热度按时间lokaqttq1#
请使用
chrome.downloads.download
。manifest.json
popup.html
popup.js
vd2z7a6w2#
这使用了
content scripts
和service worker
。manifest.json
matches.js
background.js