Test Web extension on Android

I’ve just tested and it does get triggered on desktop. I used the following code for the whole background.js:

http://paste.ubuntu.com/25796786/

Baptistou Baptiste Thémine
October 22
I have look at your code on github and I see in background.js line 100 what I described before. This is never triggered :

> 
> document.addEventListener("DOMContentLoaded", function(){ url_sync();
> }, false);

Yea but maybe it is not triggered on Android or in other browsers as behavior differs in each browser. You don’t need this listener and you can call directly the function url_sync(), maybe it will solve your problem.

If I can call it directly in the main thread than it’s better really. I’ll do that.

On Android I cannot make the background.js work in any way, so even if I put any code there, it doesn’t seem to work. So I give up here for now.

I’ve written to the mailing list of the Fennec devs, I’m waiting for an answer. I’ll write you here if I get any.

Ok. It would be nice if there were a category Android on discourse. I don’t find a lot of information concerning Firefox Android development too.
Did you try with the same addon installed from AMO? Is it the same result?

Yes, installing from a file or from AMO gives the same result that I cannot run anything from background.js nor debug it.

I guess you are calling a function which is incompatible on Android but you are unable to see any error log. Make sure you have enabled all JavaScript logs in WebIDE. :thinking:
Are you debugging in Firefox Android 56? Firefox Android Beta? or Firefox Android Nightly?

I’m debugging in 56 and also beta. Do I have to enable logs int he first place? I found this info, will test it later:

https://developer.mozilla.org/en-US/docs/Tools/WebIDE/Troubleshooting

See section “Enable Logging”.

Be sure all JS logs are enabled here in the console for each page of your addon.
image
Another thing, you are using localStorage in your addon but I am not sure it is supported on Android. See compatibility table on https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage.
Use browser.storage.local instead. See example on https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage.

I think the solution might be here :

Unfortunately Extension Auto-Installer will only work for Firefox up to including version 56.

With the current APIs it won’t be possible to port it as a WebExtension. It needs to:

  • listen on a port
  • install an extension (from a Blob or something)

It would be nice if Mozilla would offer a replacement.

I need a sync storage to be able to solve a problem and support version above and below 53. chrome.storage is async and you cannot get information in a sync way.

I enable all the logs all the time, see the image:
https://i.imgur.com/o9RcKlF.png

Still I cannot get no output from the background script.

I can install my extension wthout signing it, you can find information in the link you gave me earlier:

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Developing_WebExtensions_for_Firefox_for_Android

My only problem is to not be able to get logs from background scripts.

Dammit :neutral_face:

I think the only thing you can do is to file a bug on bugzilla. And waiting for a solution in next Firefox versions (maybe), I recommend you to verify the Android compatibility of each function you use on mozzila website. Sometimes, with localStorage for example, you will need to adapt your code with an alternative solution. For example :


//Browser compatibility
var browser = browser || chrome;
var android = !browser.windows;

if(android){
    browser.storage.local.get(function(storage){
	//Your Android code here
        console.log(storage.test);
    });
}
else{
    //Your Desktop code here
    console.log(localStorage.getItem("test"));
}

Thanks but what you wrote will not be good because I need to access the result of the aync chrome.storage from an async event.

Baptistou Baptiste Thémine
October 23

Unfortunately Extension Auto-Installer will only work for Firefox up to including version 56.

NilkasG:
Dammit :neutral_face:

I need a sync storage to be able to solve a problem and support version above and below 53. chrome.storage is async and you cannot get information in a sync way.

log69:
I think the only thing you can do is to file a bug on bugzilla. And waiting for a solution in next Firefox versions (maybe), I recommend you to verify the Android compatibility of each function you use on mozzila website. Sometimes, with localStorage for example, you will need to adapt your code with an alternative solution. For example :

> 
> //Browser compatibility
> var browser = browser || chrome;
> var android = !browser.windows; if(android){ browser.storage.local.get(function(storage){ //Your Android code here console.log(storage.test); });
> }
> else{ //Your Desktop code here console.log(localStorage.getItem("test"));
> }

This is not a problem as browser.storage.sync is not supported on Firefox Android too. See compatibility table on https://developer.mozilla.org/fr/Add-ons/WebExtensions/API/storage.
In all case you will have to do an alternative code for Android :confused:

That I am aware of :slight_smile: But I can keep this code base just like in the case of desktop version 52 using only localStorage because sync is supported from 53 on. I tested and it works on 52. So my code fallbacks to local only if no sync available.

I’m curious if there will be any answer of how we can read the log for background scripts and I’m anxious to see what works on Android and what not from what I’d like to do. Still digging for answers…

Meanwhile I’ve taken a try with this addon but it didn’t help, no log messages from my script:

https://addons.mozilla.org/en-US/android/addon/console/

I think you could solve your problem with sync vs async storage functions and Android miscompatibility with a more object-oriented approach. I created a pull request on your GitHub and tested it on Firefox and Chrome which worked well but not yet on Firefox Android :wink:

I’ll take a look at it around weekend, thanks.

Good news ! I tested my code on Firefox Android Nightly and it is working ! :grinning: