Chrome extension delay condition

前端 未结 1 733
面向向阳花
面向向阳花 2021-01-16 12:20

I have created a chrome extension which does something after its button is clicked. However I dont want it be abused so I need the its code to be executed after some time.

相关标签:
1条回答
  • 2021-01-16 13:17

    I had to make a compromise so just after the getSelected I added the following line:

    chrome.browserAction.disable(tab.Id);
    

    It disables the action button thus it cant be clicked while the script sends the data to the server, as with this extension I grab the tab url in order to store it in my database. After the ajax response and adding the following

    if(xhr.readyState==4)
    {
    message.innerHTML=xhr.responseText;
    chrome.browserAction.enable(tab.Id); /////<---THAT LINE
    }
    

    the button gets ready again to be clicked.

    I couldnt find the way to add a specific delay in seconds, this way seems stupid but its working, as the response's delay from my server is enough for switching the 2 states of the action button.

    With this, however another problem came up, which Ill write in different question.

    0 讨论(0)
提交回复
热议问题