Use of asynchronous commands in Firefox autoconfig

User Help for Mozilla Firefox
Post Reply
dweller
Posts: 6
Joined: January 4th, 2018, 7:16 am

Use of asynchronous commands in Firefox autoconfig

Post by dweller »

I'm not sure to which sub-forum this post belongs to, so i posted here.

I've been using autoconfig feature of Firefox (on Windows), normally used in enterpise environment, as final part of customized setup i use in personal setup (i'm not redistributing it). Note that i'm not versed in JS/XPCOM and have used code from other (more knowledgeable) people to make my autoconfig.

In past, i used XPCOM to execute UI, preference and addon customizations.

Since XPCOM will be abandoned in addons, i have to ask : will XPCOM continue to be available to entrprise enviroment admins for autoconfigs ?

If answer to the above is "no", would anyone please provide a working example ?

Here is a short list of prerequisites for a quick test for FF 57 Quantum :
- enable developer tools in prefs via devtools.chrome.enabled = true
- open browser console via Ctrl+Shift+J
- copy/paste the following in browser console (remember ENTER runs commands/scripts , newline is SHIFT+ENTER)
- it may be needed to run Components.utils.import ("resource://gre/modules/osfile.jsm") prior to running this

Code: Select all

var x=[];
async function test()
  {
    x = await OS.File.read(OS.Path.join(OS.Constants.Path.profileDir,"containers.json")); //just an example file
  }
console.log("content\n" + String.fromCharCode.apply(null,x)); // extra conversion for getting usable string
There won't be any output.

I've looked through (rather extensive) docs and only found that this is a "promise", a asynchronous execution and that does not halt code execution, so any commands executed synchronously will fail because of invalid/undefined result.

I was looking through many examples but none provide a complete working source that will execute synchronously.
I tried with Task.spawn(), async function(), await, yield etc.

And before anyone says "use .then()" : yes indeed valid result will be available, but is it expected from admins/devs to move ENTIRE source inside .then() ? I really just need an example how to force new API functions back into synchronous execution and make them reliable again.

Interestingly, as browser console environment retains variables between executions, variable x in the above example will contain data shortly after test script is run. That's why i added "var x=[];" at beginning to avoid possible confusion on repeated runs.
Post Reply