2

tl;dr:关于 QUOTA_BYTES_PER_ITEM 的同步错误,但我的项目很小,需要帮助找出问题所在。

因此,我在 Google Chrome 扩展程序上遇到了这个错误,我认为这没有多大意义,因为我要保存的内容不会超过 400 字节(序列化,大于JSON 字符串),并且考虑到,QUOTA_BYTES_PER_ITEM4096远非该限制。

要么我计算错误(很可能),要么我做错了(并非不可能!)。

您可以查看我的扩展程序的代码并从网上商店安装它

对这个问题很重要的部分如下(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 代码以对每个设置使用不同的键/值,而不是对象,但我认为这没有多大意义,因为此同步功能被宣传为支持对象(而且这个很小),所以我希望我只是做错了什么。

谢谢!

4

1 回答 1

3

所以我整理了一下。

The main issue was an "infinite loop" (n00b) I had because of the onChanged listener for chrome.storage ( https://developer.chrome.com/extensions/storage.html#event-onChanged ), where I'd save the settings every time there was a change detected.

I didn't read the documentation carefully enough and thought this was to "listen" for changes in the settings that came, for example, from a sync (but it listens to any change), and since I can get the settings from sync, I don't even need it.

Removing that listener fixed the problem.

The new version of the extension (1.0.4) is bug-free as far as I'm aware.

于 2013-01-04T18:41:28.223 回答