我的 Chrome 扩展程序有问题,具体是 list 文件有问题。
{
"manifest_version": 2,
"permissions": [
"file://*/*",
"activeTab",
"http://www.pdfzorro.com/"
],
"name": "PDFzorro - PDF Editor",
"version": "0.0.0.11",
"short_name": "PDF-Dateien bearbeiten - edit PDF files",
"description": "edit PDF files online, direct from GoogleDrive",
"icons": { "16": "logo16.png",
"128": "logo.png" },
"container": ["GOOGLE_DRIVE"],
"api_console_project_id": "000000000000",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
在 Dev-Mod 中,扩展程序可以在 Chrome 中运行。但我无法将压缩的扩展程序上传到 Chrome 网上应用店。
Error: Schema "file://" not allowed in "permissions"
我也尝试过:
file:///
file://
file:///*
file://*/*
..但没有任何效果。
应用程序工作和上传工作的唯一方法是添加 <all_urls>
到权限。但我不希望获得此权限,因为安装应用程序时会出现警告。
最佳答案
您可以声明"<all_urls>"
作为optional permission并在运行时请求原点。
只要将其设置为可选权限,就会显示“允许访问文件:URL”复选框,用户无论如何都需要勾选。
您可以找出该标志的状态,因为除非设置了原点,否则原点将被视为无效。所以:
chrome.permissions.contains(
{origins: ["file://*"]},
function(granted){
if(chrome.runtime.lastError) {
// The flag is not set
// You need to explain it to the user and then show the page
// You can open the page scrolled where you need it with the following:
// chrome.tabs.create({ url: "chrome://extensions?id=" + chrome.runtime.id });
// Note that just a link won't work
} else if(!granted) {
// The flag is set, but the permissions are not yet granted
// You need to call the next snippet FROM A USER GESTURE (e.g. click)
} else {
// Everything is peachy, you have the permissions
}
}
);
勾选该标志后,您可以通过用户手势调用以下命令来获取权限:
chrome.permissions.request(
{origins: ["file://*"]},
function(granted) {
if(!granted) {
// Should never happen (see below)
} else {
// Everything is peachy now
}
}
);
只要设置了标志,这将总是成功,无需向用户发出对话框,但必须通过用户手势调用一次。权限授予在整个安装生命周期内持续存在。
这不会在安装时生成警告,CWS 应该能够通过。
关于javascript - Chrome 扩展程序 : Schema "file://" not allowed in "permissions",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30484458/