On the button click, I request full access via chrome's chrome.permissions.request api:$('#button-requestpermissions').click(function(){ requestAmbientPermission(function(granted) { if (granted) { // code never reached as granted === false } });});function requestAmbientPermission(callback){ // Permissions must be requested from inside a user gesture, like a button's click handler. chrome.permissions.request({ permissions: ['activeTab'], origins: ['<all_urls>'] }, callback);}清单具有如下所示的可选权限:The manifest has optional permissions set like so: "permissions": [ "https://www.meethue.com/", "https://colorlovers.herokuapp.com/" ], "optional_permissions": [ "activeTab", "<all_urls>" ],推荐答案来不及回答?您只能通过用户操作请求新的权限,例如,单击的按钮:Too late to answer? You can only request a new permission from a user action, for example, a button clicked:document.querySelector('#my-button').addEventListener('click', function(event) { // Permissions must be requested from inside a user gesture, like a button's // click handler. chrome.permissions.request({ permissions: ['tabs'], origins: ['http://www.google.com/'] }, function(granted) { // The callback argument will be true if the user granted the permissions. if (granted) { doSomething(); } else { doSomethingElse(); } });});可以在此处 这篇关于Chrome扩展程序:必须在用户手势期间调用该函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 06:09