Unchecked runtime.lastError when using Chrome API

后端 未结 3 2239
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 10:40

I use chrome.fileSystem API in my app to open a file. When I click the Cancel button of the file chooser dialog, an error occurs:

3条回答
  •  情歌与酒
    2020-11-28 10:55

    For this type of errors try catch won't be helpful. Instead you can access the global variable chrome.runtime.lastError as @xan mentioned in his awesome response above(by the way you should read it and upvote it!).

    Now, here I provide an example that can be used:

    function catchLastError(){
      if(chrome.runtime.lastError){
        console.log("error: ", chrome.runtime.lastError);
      }else{
        // some code goes here.
      }
    }
    
    chrome.fileSystem.chooseEntry(yourEntry,catchLastError);
    

提交回复
热议问题