2

I am having a problem with the Chrome browser and not Firefox.

Paused on exception ReferenceError: browser is not defined

ReferenceError: browser is not defined at shouldWrapAPIs (polyfill.js:228) at polyfill.js:250

I can’t identify the cause of the problem, only that it happens in Chrome and not Firefox.

Could someone give me some help indicating what causes that problem?

It shows me in polyfill.js the following. indicating precisely the following line

return !(browser.storage.local.get() instanceof Promise);

function shouldWrapAPIs()
{
try
{
return !(browser.storage.local.get() instanceof Promise);
}
catch (error)
{
}

return true;
}

As indicated by error in the line return! (Browser.storage.local.get () instanceof Promise); I consider that it is an error that possibly comes from saving or storing data in the browser.

I save data in the browser with the following API.

export async function setItem(key: string, value: any) {
  await Storage.set({
    key: key,
    value: value
  });
}

export async function getItem(key: string) : Promise<any>{
  const { value } = await Storage.get({ key: key});
  return value;
}
export async function removeItem(key: string) {
  await Storage.remove({ key: key });
}

Is it possible that the problem comes from there?

I use the API for example as shown in the following code:

  axios.get(url+"1"+"/"+user+"/"+email)
  .then((res: { data: any; }) => {
    const resquest = res.data;
    console.log(res.data)
    if(resquest==="User alredy taken"){
      onShowAlert();
    }
    else{
        setItem("isRegistered", user );
        setItem("infoCompleted", false);
        setItem("clientType", "1");
        setCount(5);
    }
  })

Thanks in advance.

JAOdev
  • 301
  • 3
  • 11

1 Answers1

1

Chrome uses property chrome.storage

Here is an article explaining this - https://developer.chrome.com/docs/extensions/reference/storage/

kirillman
  • 79
  • 1
  • 8
  • Thanks. The problem is that I want the application to be cross-platform and run the same in all browsers. – JAOdev Feb 24 '21 at 16:05
  • 1
    @JAOdev I'm not a master in this, but I think that your app needs to detect which browser it is using and after that change ```browser``` variable based on which browser user is loading it. All I could find is this article - https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – kirillman Feb 24 '21 at 18:21
  • The problem was fixed by disabling Adblock – JAOdev Feb 24 '21 at 19:00
  • Didn't expect this haha. Thanks for letting me know – kirillman Feb 24 '21 at 19:49