Web-extension compatibility in the cookieStore

January 9th, 2018

Since Firefox embraced the Web-extension API, life is easier for developers: extensions should be compatible with Chrome, Opera, Firefox, Edge, and Firefox Mobile.

So Firefox Android became my favorite mobile browser, because it’s the first mobile browser to support extensions. Well, there was a lab version of Opera Mobile (Presto), but that died even earlier then Presto died, unfortunately.

But it’s not all sunshine. There are quirks, and incompatibilities in webextensions. Of course you would say. And I’m talking about more then just the chrome/browser name-space differences.

Take cookies and cookiestores.

cookies.getAllCookieStores()

Browser vendors use different storeId’s, but do not really document it.

Chromium/Opera/Chrome storeId ‘s

  • “0” for default windows
  • “1” for private windows

Firefox uses different storeId’s

  • “firefox-default” for normal windows
  • “firefox-private” for private windows.

How to set a cookie

Here some examples to evade the cookie-wall of Volkskrant.nl newspaper by setting cookies.

For a default Firefox window

browser.cookies.set(
 { url: "https://www.volkskrant.nl",domain: ".volkskrant.nl", name: "nl_cookiewall_version", value:"1", storeId:"firefox-default"}
 );

For a Firefox private window

browser.cookies.set(
 { url: "https://www.volkskrant.nl",domain: ".volkskrant.nl", name: "nl_cookiewall_version", value:"1", storeId:"firefox-private"}
 );

For a Chromium/Opera/Chrome default window

chrome.cookies.set(
 { url: "https://www.volkskrant.nl",domain: ".volkskrant.nl", name: "nl_cookiewall_version", value:"1", storeId:"0"}
 );

For a Chromium/Opera/Chrome private window

chrome.cookies.set(
 { url: "https://www.volkskrant.nl",domain: ".volkskrant.nl", name: "nl_cookiewall_version", value:"1", storeId:"1"}
 );

 

 

Leave a Reply