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