Test Web extension on Android

Hi Guys,

I can use WebIDE connecting to my Android phone through WiFi. It sees my phone and I get the dev tools. It works nicely.

I’d like to test and debug my web extension. Is there an option in Fennec (Firefox for Android) similar to the desktop version like the page about:debugging where I can upload an extension for testing without releasing in AMO?

Thanks.

1 Like
1 Like

This makes it clear. Thank you Baptiste, You’ve been of great help.

I could install my extension on the phone as described in the documentation that you linked.

However my background script does not run at all. This is the first place I wanted to debug it on Android because I had problem with my extension installed from AMO too.

So background.js does not get called on any events that I specify. I place a console.log(“something”) code in many places and the log does not appear in the console of the WebIDE (though it is connected to my phone and I can reload the page through the IDE so everything seems to be working fine). Could you direct me how I could debug that when I don’t have console output? Thanks.

This is normal. I guess you are placing your code in window.onload or something like that but it is never triggered in background script. You should place the code directly in background.js.


//background.js
console.log("Hello World !") //Code executed

window.onload = function(){
    console.log("Hello World !") //Code never executed
};

If my background.js consists of a single line of console.log, it still doesn’t work.

I tested it and I get console messages from the content script, but not from the background. Why could this be?

Baptistou Baptiste Thémine
October 22
This is normal. I guess you are placing your code in window.onload or something like that but it is never triggered in background script. You should place the code directly in background.js.

> 
> //background.js
> console.log("Hello World !") //Code executed window.onload = function(){ console.log("Hello World !") //Code never executed
> };

Currently, I am also facing difficulties in debugging my addon on Android. API’s are partially supported and some issues exists also. How is your manifest.json ?

With your help I’ve developed this addon, you can see here my code including the manifest file:

https://github.com/log69/yesscript2

I can do anything from the content script (foreground) but cannot do anything from the background. I cannot debug or test anything like this unfortunately. Thanks for your help anyway.

I’m reading this page now but doesn’t help so far:

https://stackoverflow.com/questions/3829150/google-chrome-extension-console-log-from-background-page

I’m still looking for answers.

Actually the answer at the following link explains the behavior and confirms that the logs from the background go to different place, though it is for Chrome:

https://stackoverflow.com/a/17293612

BTW, is there any more relevant forum to reach the Fennec developers?

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);

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 :