tl;dr:关于 QUOTA_BYTES_PER_ITEM 的同步错误,但我的项目很小,需要帮助找出问题所在。
因此,我在 Google Chrome 扩展程序上遇到了这个错误,我认为这没有多大意义,因为我要保存的内容不会超过 400 字节(序列化,大于JSON 字符串),并且考虑到,QUOTA_BYTES_PER_ITEM它4096远非该限制。
要么我计算错误(很可能),要么我做错了(并非不可能!)。
对这个问题很重要的部分如下(CoffeeScript):
# Object: Default settings
defaultSettings =
    type: 'single'
    chars: 14
    howmany: 1
    security:
        lowercase: true
        uppercase: true
        special: true
        punctuation: true
        readable: false
# Object: Current settings
paGenSettings = defaultSettings
# Function: Save Settings
saveSettings = (settings, notify) ->
    if validateSettings settings, true
        # Save settings using the Chrome extension storage API. Try sync, fallback to local
            window.chrome.storage.sync.set { settings: settings }, () ->
                if chrome.runtime.lastError && chrome.runtime.lastError.message && chrome.runtime.lastError.message.indexOf( 'MAX_WRITE_OPERATIONS_PER_HOUR' ) != -1
                    window.chrome.storage.local.set { settings: settings }, () ->
                        paGenSettings = settings
                        if notify
                            showNotification window.chrome.i18n.getMessage( 'settingsSaved' )
                        applySettings()
                        true
                else
                    paGenSettings = settings
                    if notify
                        showNotification window.chrome.i18n.getMessage( 'settingsSaved' )
                    applySettings()
                    true
    true
    else
        false
# Function: Get Settings
getSettings = () ->
    # Get settings using the Chrome extension storage API. Try sync, fallback to local
    window.chrome.storage.sync.get 'settings', (items) ->
        if items.settings
            settings = extend( paGenSettings, items.settings)
            if validateSettings settings, false
                paGenSettings = settings
                applySettings()
            true
        else
            window.chrome.storage.local.get 'settings', (items) ->
                if items.settings
                    settings = extend( paGenSettings, items.settings)
                    if validateSettings settings, false
                        paGenSettings = settings
                applySettings()
            true
如果您检查它,当您保存设置或生成密码(也保存设置)时,您会看到弹出以下错误:
storage.set 期间出错:超出 QUOTA_BYTES_PER_ITEM 配额。
我已经让它回退到本地存储,但我真的希望它能够同步设置。
因此,如果这不起作用,我将更改 get/set 代码以对每个设置使用不同的键/值,而不是对象,但我认为这没有多大意义,因为此同步功能被宣传为支持对象(而且这个很小),所以我希望我只是做错了什么。
谢谢!