0

I have a chrome extension that uses the Omnibox API. I want to port this extension to firefox by myself.

I've tried nearly everything that may help, and miserably, I'm exhausted and out of solutions.

Anyway, the extension basically does these steps in Chrome with no errors:

  1. Load global variable called sites which is an array of object
var sites = [
    {
        "name":"ytb",
        "desc":"YouTube",
        "url":"https://www.youtube.com/results?search_query={%query%}"
    },
    {
        "name":"ggl",
        "desc":"Google",
        "url":"https://www.google.com/search?q={%query%}"
    },
    {
        "name":"dvand",
        "desc": "Android Devs",
        "url": "https://developer.android.com/s/results?q={%query%}"
    },
    {
        "name":"bng",
        "desc":"Bing",
        "url":"https://www.bing.com/search?q={%query%}"
    },
...
];
  1. Save sites object to storage.local on runtime.onInstalled:
browser.runtime.onInstalled.addListener((details) => {
    if (details.reason == "install") {
        console.log("First install");
        save(); //which saves sites to local storage...
        load(); //which load sites from local storage...
    }
});

Here is the save and load functions:

function save() {
    browser.storage.local.set({"ssearch_sites":sites}, () => {
        console.log("Saved!",sites);
        sites = sites;
    });
}
function load() {
    browser.storage.local.get('ssearch_sites', (res) => {
        console.log("Got!",res.ssearch_sites);
        sites = res.ssearch_sites;
    });
}

I think the problems could be relying on these:

  • onInstalled is not working
  • global variables such as sites are not stored (which is not quite possible).
  • local storage api is not working very well...

Oh, and I must say, when

I run the extension from these:

web-ext run

It works sometimes as expected, but when I download it from the store, it does not work. How could this even possible? I mean how works on testing and does not work on the production stage?

One more thing, do you know an alternative to local storage API?

Thanks!

Source codes are here:

Google Chrome version

Firefox version

  • The idea of saving `onInstall` is simple, saving for use another time, necessary? Yes for manipulating `sites`... In source code, you'll understand why –  May 11 '20 at 07:47
  • This project is for less typing and searching effectively. General usage is sth like this: `@ `... Perfectly works on Chrome BTW... –  May 11 '20 at 07:49
  • I don't see how the posted fragments of code are related to the problem. The closest thing to a problem I see in these snippets is that 1) `load()` call is not needed at all and 2) `sites = sites` is a no-op - it does nothing at all - you probably meant window.sites = sites but even that isn't needed. Someone, preferably you, should actually [debug the background script](https://extensionworkshop.com/documentation/develop/debugging/) in devtools. – wOxxOm May 11 '20 at 07:52
  • @wOxxOm yes, unnecessary. But I don't think it's the problem. Thanks for the tip. –  May 11 '20 at 15:30

0 Answers0