OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Chrome extension: function must be called during a user gesture

  • Thread starter Thread starter Dmitry Sadakov
  • Start date Start date
D

Dmitry Sadakov

Guest
In a Chrome Extension I want to ask the user for full access to pages through a browser_action's popup's link (aka a toolbar popup with a link). When the user clicks the link, I get this error:

runtime.lastError while running permissions.request: This function must be called during a user gesture

Yet the user actually clicked the link and the 'user gesture'. Any ideas of how to debug what is considered a user gesture?

On the button click, I request full access via chrome's chrome.permissions.request api:

Code:
$('#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:

Code:
  "permissions": [
    "https://www.meethue.com/",
    "https://colorlovers.herokuapp.com/"
  ],
  "optional_permissions": [ 
    "activeTab",
    "<all_urls>"
  ],

<p>In a Chrome Extension I want to ask the user for full access to pages through a browser_action's popup's link (aka a toolbar popup with a link). When the user clicks the link, I get this error:</p>

<p><code>runtime.lastError while running permissions.request: This function must be called during a user gesture</code></p>

<p>Yet the user actually clicked the link and the 'user gesture'. Any ideas of how to debug what is considered a user gesture?</p>

<p>On the button click, I request full access via chrome's <a href="https://developer.chrome.com/extensions/permissions" rel="nofollow"><code>chrome.permissions.request</code></a> api:</p>

<pre><code>$('#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);
}
</code></pre>

<p>The manifest has optional permissions set like so:</p>

<pre><code> "permissions": [
"https://www.meethue.com/",
"https://colorlovers.herokuapp.com/"
],
"optional_permissions": [
"activeTab",
"<all_urls>"
],
</code></pre>
 
Top