Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

javascript - Chrome扩展程序| 当我尝试从chrome.storage.sync获取存储的值时,“ IO错误:…/ LOCK:没有更多详细信息。”(Chrome extension | “IO error: …/LOCK: No further details.” when I try to get stored values from chrome.storage.sync)

If I launch the chrome browser and immediately click on my extension icon, I am getting this error

(如果我启动chrome浏览器并立即点击扩展程序图标,则会收到此错误)

IO error: .../LOCK: No further details.

(IO错误:... / LOCK:无更多详细信息。)

(ChromeMethodBFE: 15::LockFile::1)

((ChromeMethodBFE:15 :: LockFile :: 1))

This error is from chrome.storage.sync.get() in background.js .

(此错误是由chrome.storage.sync.get()background.js 。)

Also the value of result in the callback function is undefined when this error occurs.

(当发生此错误时,回调函数中的result值也是undefined 。)

The error is not persistent.

(该错误不是永久性的。)

Sometimes I get this error and sometimes I do not.

(有时我会收到此错误,有时却没有。)

I switched from chrome.storage.local to chrome.storage.sync to see if it helps.

(我从chrome.storage.local切换到chrome.storage.sync以查看是否有帮助。)

But no, it didn't.

(但是,没有。)

I uninstalled the extension and installed again.

(我卸载了扩展程序并重新安装。)

Didn't work.

(没用)

I even reinstalled chrome.

(我什至重新安装了chrome。)

I have googled this error and found this and this , but to no avail.

(我已经用谷歌搜索了这个错误并找到了这个这个 ,但是没有用。)

I have been working on this problem all day and as a final resort I am posting here.

(我整天都在研究这个问题,作为最后的手段,我在这里发布。)

popup.js

(popup.js)

$(document).ready(function() {

 var access_token;

  // Send message to background.js
  chrome.runtime.sendMessage({msg: "getToken"}, function(token) {
    if(token) {
      access_token = token;
      userLoggedIn();
    } else {
      showLoginPage();
    }
  });

  chrome.storage.onChanged.addListener(function (changes,areaName) {
    if(changes.token.newValue) {
      access_token = changes.token.newValue;
      userLoggedIn();
    } else {
      showLoginPage();
    }

  });

 // When clicked on login button, this will launch an oauth window and save token in storage. This is working fine.
 $('#login-btn').click(function() {
   chrome.extension.getBackgroundPage().getAccessToken();
 });

 // When user logs out, this will revoke the oauth token, this is working fine.
 $('#logout-btn').click(function() {
   chrome.extension.getBackgroundPage().revokeAccessToken(access_token);
 });

});

background.js

(background.js)

var token;

// Check for token in storage
function checkAccessToken() {
  chrome.storage.sync.get("token", function(result){

    if(chrome.runtime.lastError) {
      console.log(chrome.runtime.lastError.message); // Error here
    } else {
      if('token' in result) {
        token = result.token;
      }

    }
  });
}

checkAccessToken();

// Listen to messages from popup.js
chrome.runtime.onMessage.addListener(
 function(request, sender, sendResponse) {
   if (request.msg === "getToken") {
     sendResponse(token);
   }
 });

function getAccessToken() {
  // code
}

function revokeAccessToken(token) {
  // code
}

manifest.json

(manifest.json)

{
  "name": "Name",
  "short_name": "name",
  "description": "Description",
  "version": "0.1",
  "manifest_version": 2,
  "browser_action": {
    "default_icon": "import.png",
    "default_popup": "popup.html"
  },
  "background": {
    "scripts": ["jquery-3.4.1.min.js", "background.js"],
    "persistent": true
  },
  "icons": { "64": "import.png" },
  "permissions": [ 
    "identity", 
    "<all_urls>",
    "storage" 
  ]
}
  ask by TheGuy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...