Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot call browser.storage.local.get with callback; Error: Expected at most 1 argument for get(), got 2 #102

Open
mikhoul opened this issue Apr 6, 2018 · 4 comments

Comments

@mikhoul
Copy link

mikhoul commented Apr 6, 2018

Hi,

I've found this polyfill and tried to convert a Firefox addon to AMO but it don't work, it throw error in the console window: each time I load the extension in Chromium: https://i.imgur.com/l9JZ5dB.png

I've load the polyfill via the manifest.json like in the exemple on the readme.

Here's a link to the source of the addon in case you need it: https://dl.dropboxusercontent.com/s/68ph7gwzoltrktv/TranslateExtension.zip

Regards :octocat:

@Rob--W
Copy link
Member

Rob--W commented Apr 6, 2018

You shouldn't use the file from src/, but the output in dist/.
#47 has documented how you can obtain pre-built polyfill files.

@Rob--W Rob--W closed this as completed Apr 6, 2018
@mikhoul
Copy link
Author

mikhoul commented Apr 6, 2018

Thanks @Rob--W I used the pre-built version and now I have this error: https://i.imgur.com/OV8Da6X.png

What can I do to resolve it and having the addon working on Chromium ?

Regards :octocat:

@Rob--W
Copy link
Member

Rob--W commented Apr 6, 2018

That's because you're using:

    function getSettings() {
        return new Promise(function (resolve, reject) {
            browser.storage.local.get("Settings", function (value) {
                Settings = value.Settings;
                resolve(Settings);
            });
        })
    }

That should work (it is a bug in the polyfill if it does not), but a work-around is to use:

    function getSettings() {
        return new Promise(function (resolve, reject) {
            browser.storage.local.get("Settings").then(function (value) {
                Settings = value.Settings;
                resolve(Settings);
            });
        })
    }

But with this polyfill, you don't need to wrap in a Promise constructor, and you can just use:

    function getSettings() {
        return browser.storage.local.get("Settings").then(function (value) {
            Settings = value.Settings;
            return Settings;
        });
    }

or even with async/await syntax:

    async function getSettings() {
        let value = await browser.storage.local.get("Settings");
        Settings = value.settings;
        return Settings;
    }

@Rob--W Rob--W changed the title Problem porting an addon to Chromium Cannot call browser.storage.local.get with callback; Error: Expected at most 1 argument for get(), got 2 Apr 6, 2018
@Rob--W Rob--W reopened this Apr 6, 2018
@mikhoul
Copy link
Author

mikhoul commented Apr 6, 2018

@Rob--W Another small error here after I 've applied the workaround: https://i.imgur.com/6jpaxSJ.png

Thanks for your help and time :octocat:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants