小编Abh*_*hek的帖子

尽管从chrome本地存储中获取了未设置的变量,chrome.runtime.lastError仍然是'UNDEFINED',

我试图检查是否已在chrome.storage.local中设置了键值对.因为我在这里采取了类似的问题的帮助.这里我试图从存储中获取的变量尚未设置.当我尝试使用lastError捕获错误.它是未定义的,而假设由于读取先前未设置的变量(根据我用googled)的错误而定义和设置.请在读取尚未设置的变量时帮助我检测错误.

的manifest.json

{
    "name": "TestExtension",
    "version": "1.0",
    "manifest_version": 2,
    "background": {
        "scripts": ["jquery.js", "background.js"]
    },

    "description": "Test the extension features here",
    "icons": {
        "16": "images/16x16.png",
        "48": "images/48x48.png",
        "128": "images/128x128.png"
    },

    "page_action": {
        "default_icon": {
            "19": "images/19x19.png",
            "38": "images/38x38.png"
        },
        "default_title": "Test Plugin default title",
        "default_popup": "popup.html"
    },

    "permissions": ["tabs", "storage", "http://*/*", "https://*/*"]
}
Run Code Online (Sandbox Code Playgroud)

background.js

function showTheExtension(tabId, changeInfo, tab) {
    console.log("Extension loaded");
    chrome.pageAction.show(tabId);
} // ---EOF checkForValidUrl---
chrome.tabs.onUpdated.addListener(showTheExtension);
Run Code Online (Sandbox Code Playgroud)

popup.js

$('document').ready(function() {
    chrome.storage.local.get('testVar1', function(result) {
        if (chrome.runtime.lastError) { …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

1
推荐指数
1
解决办法
3130
查看次数