Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for Android (how to inject the config files) #318

Closed
TerkiKerel opened this issue Dec 24, 2017 · 24 comments

Comments

@TerkiKerel
Copy link

commented Dec 24, 2017

Hi,

the new web-extension API does not allow add-ons to edit about:config references. We can change the user.js file on our desktop operating systems. But how we can edit user.js on mobile Android Firefox? We can change them manually from about:config but these takes long time. Also I always reset my settings/or I reset the mobile phone completely. It is difficult to set all these settings from mobile.

It would be great if you have an idea for Android Firefox.

Thank you

@Atavic

This comment has been minimized.

Copy link

commented Dec 24, 2017

The entire Mozilla profile is not visible to the non-rooted Android user.

http://codeverge.com/mozilla.support.firefox/why-would-mozilla-developers-disallow/2044673

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Dec 25, 2017

Nothing much you can do except root the phone - its an Android permissions thing, only the owner app can access its stash, so unless Mozilla build that in, and I doubt it, it'll have to be manually via about:config

FF accounts can sync some stuff, FWIW (not much, search for services.sync.prefs in about:config)

@TerkiKerel

This comment has been minimized.

Copy link
Author

commented Dec 29, 2017

@Thorin-Oakenpants but many users use non-rooted phone. %99 of user.js preferences are about privacy and you are telling me to use sync (the cloud thing) ? :)

There should be tricks to change the preferences. The only way is not to use user.js file. For example:

1- we can try to write user-script for Greasemonkey or violentmonkey which executes a script on about:config page ?

2- remote debugging about:config page from destkop firefox ?

3- execute a javascript from url-bar (like bookmarklet) ?

Or any other tricks/ideas?

Thank you

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Dec 29, 2017

1- With the removal of XUL, you cannot change about:config entries via extensions (some are available thru APIs, but very little).

3- pretty sure you can't run JS from the urlbar (or its a pref we set for security reasons)

2- remote debugging?

Well, we can reset prefs via Scratchpad using scripts - see https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.1-Resetting-Inactive-Prefs-%5BScripts%5D#small_orange_diamond-how-to-run-a-scratchpad-script . Is scratchpad available on mobile, and can the scratchpad write values?

@Atavic

This comment has been minimized.

Copy link

commented Dec 29, 2017

2 - Android has strict permissions and a single user by default.

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Dec 29, 2017

Can't find any way to bring up a Scratchpad or other tools in FF on Android. - Menu>Settings>Advanced>Remote Debugging via USB> toggle on/off .. now what.

https://developer.mozilla.org/en-US/docs/Tools/Remote_Debugging/Debugging_Firefox_for_Android_with_WebIDE

https://www.howtogeek.com/125769/how-to-install-and-use-abd-the-android-debug-bridge-utility/

All this is about as much work as rooting your phone .. 99% of people aren't gonna do it .. and that's IF its still even possible to run a script to change prefs

@TerkiKerel

This comment has been minimized.

Copy link
Author

commented Dec 30, 2017

I try remote debugging from my desktop Firefox. I did not installed any extension or ADB on my operating system. It is very easy to debug remote android.

I write a simple javascript to execute on about:config page. I tested it. I write it here. maybe someone will need it.

var user_pref = function(pref, val){

  try{
    if(typeof val == "string"){

         Services.prefs.setStringPref(pref, val);      
    }
    else if(typeof val == "number"){

         Services.prefs.setIntPref(pref, val);      
    }
    else if(typeof val == "boolean"){

         Services.prefs.setBoolPref(pref, val);      
    }
  } catch(e){
    console.log("pref:" + pref + " val:" + val + " e:" + e);
  }
}
//paste your user.js file content here
@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Dec 30, 2017

So this works then? You can apply all your changes in a single script? Do the prefs pasted underneath only take the active ones? I take it you were running 57+? I've never connected via remote debugging, we'll need proper documentation on steps, which we should write up as a wiki page

@TerkiKerel

This comment has been minimized.

Copy link
Author

commented Dec 31, 2017

@Thorin-Oakenpants yes it works. I tested it.

First you start remote debugging from desktop Firefox (without any extension or Android-SDK). Desktop Firefox has build-in WebIDE module. After you connect to android firefox app, you go to about:config page. You can also inject a script to a web page that opened from Android. Copy my script, also copy your userjs file below it, and execute whole script to android firefox.

I am using:

  • desktop Firefox 57.0.3
  • android mobile firefox beta 58.0b12
  • android mobile firefox stable 57.0.1

"only take the active ones?" --> I don't know if I understand your question exactly. But I see this: If I will call my user_pref method with any parameter it works. I mean If I have "media.navigator.this.pref.is.not.exist" it works. But does it matters ? Who cares if I have a pref which is not using by anyone?...

I think this topic should be clearly documented. Mobile privacy is more terrible status than Desktop.

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Jan 1, 2018

"only take the active ones?" --> I don't know if I understand your question exactly.

your code
//paste your user.js file content here

// user_pref("one", "this is an inactive pref as it is commented out")
user_pref("one", "this is an active pref as it is not commented out")

Stupid question (forgot to screw my head on), because the inactive prefs are comment lines and won't be executed. Just want to check that FF reads all the syntax OK and doesn't try to parse something silly

I think this topic should be clearly documented

Agree

But does it matters ?

Nah, it's just a pref entry that will do nothing and never be called

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Jan 15, 2018

Do I have to do everything? /s

Should we create a wiki page 1.6 Android [non-rooted]

@Atavic

This comment has been minimized.

Copy link

commented Jan 15, 2018

👍 Android [Generic]

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Jan 16, 2018

I don't quiet like the name, but generic doesn't mean anything. The page can also have the basic info to stop FF, force unload it, and where to put the user.js, so basically a sentence or two about rooted, but the whole thing is mainly about non-rooted. I'd probably just call the page Android

...but my question wasn't about the name, it was should we do the page

@Atavic

This comment has been minimized.

Copy link

commented Jan 16, 2018

I didn't mean that as title, but as an idea that a wiki page for non-rooted devices only seems limited IMHO

@icpantsparti

This comment has been minimized.

Copy link

commented Jan 20, 2018

I managed to set some Firefox preferences on my non-root Android using TerkiKerel's javascript. It is straight forward, but not entirely obvious at first. Here are some notes which might help towards an Android wiki page.

Using remote debugging to inject user.js preferences to Android Firefox

1) Choose a) Wi-Fi (easier) or b) USB connection

1a) Connecting Firefox on your Desktop Computer and Android Device via Wi-Fi

mozilla - Debugging_Firefox_for_Android_over_Wifi

  • Install the ZXing Team Barcode Scanner Android app
  • Enable "Remote debugging via Wi-Fi" on Android Firefox (Options|Settings|Advanced)
  • (You might have to toggle this off/on later if troubleshooting)
  • On desktop Firefox visit and set true: about:config?filter=devtools.webide.enabled
  • Open WebIDE on desktop Firefox (Shift+F8 or menu|Tools|Web Developer)
  • Click "Refresh Devices" icon (upper right), click on your Android device
  • Scan the QR code with your Android to connect

Troubleshooting, if the device is not seen (note any settings changes for reversal later):
(Visit the troubleshooting link on the Mozilla page for more details.)

  • Is desktop firewall stopping connection?
  • Is Android firewall app stopping connection? (eg NetGuard, No-root firewall, etc)
  • Is Network/router settings/firewall stopping connection?
  • Desktop needs to be on Wi-Fi too and not wired? (wired can work)
  • Desktop firefox version is too much older than Android firefox?

1b) Connecting Firefox on your Desktop Computer and Android Device with a USB cable

mozilla - Debugging_Firefox_for_Android_with_WebIDE

  • Enable "Remote debugging via USB" on Android Firefox (Options|Settings|Advanced)
  • Enable Android's "USB debugging" (Settings app|Developer options)
  • (You might have to toggle either of these off/on later if troubleshooting.)
    Note: to unhide "Developer options" tap "Build number" 7 times (Settings app|About Device)
  • Watch out for any Android allow/connect prompts.
  • On desktop Firefox visit and set true: about:config?filter=devtools.webide.enabled
  • Open WebIDE on desktop Firefox (Shift+F8 or menu|Tools|Web Developer)
  • You need the ADB Helper Add-on (menu|Project|Manage Extra Components)
  • (Click uninstall/install to update, or get it here if you have trouble.)
  • Click "Refresh Devices" icon (upper right), click on your Android device

Troubleshooting, if the device is not seen (note any settings changes for reversal later):
(Click the troubleshooting link on the Mozilla page for more details.)

  • Did you plug in your USB cable? ;-D
  • Windows: you might need to install Google USB Driver from Android SDK?
  • Linux: you may need a /etc/udev/rules.d/51-android.rules file, then restart udev (or reboot)?
  • Linux: you might need to install android-tools-adb / adb? (it can work without)
  • Desktop firefox version is too much older than Android firefox?

2) Remote access

  • Open "about:config" page on Android Firefox
  • It will show under WebIDE "TABS" on Desktop Firefox too (use tabs refresh icon)
  • Click the remote tab name and the "web developer tools" panel will open
  • (if you exit the panel by accident use: F12 or Project|Debug App)
  • Select the "Scratchpad" button
  • (If there is no button for "Scratchpad" click the cog and enable it)

3) Inject the preferences

  • Paste the javascript (by TerkiKerel), and your user.js into the scratchpad
  • var user_pref = function(pref, val){
      try{
        if(typeof val == "string"){
             Services.prefs.setStringPref(pref, val);      
        }
        else if(typeof val == "number"){
             Services.prefs.setIntPref(pref, val);      
        }
        else if(typeof val == "boolean"){
             Services.prefs.setBoolPref(pref, val);      
        }
      } catch(e){
        console.log("pref:" + pref + " val:" + val + " e:" + e);
      }
    }
    //paste your user.js file content here
  • The script sets a function called user_pref so wherever that appears in the rest of the code (ie in the part from your user.js) that function is called to set the user preference. Any code for preferences that are commented out will not be run. If a preference name does not exist or is mistyped it will still be created without any warnings.
  • Use "Display" (Ctrl+L) to run the javascript as it adds a result message in a comment after the script, which will say "undefined" or show errors.
  • Also click the "Console" button to look for any other error messages.
  • If errors occur on a line, the script might have stopped at that line, and you will need to correct the error in the code and re-run.
  • Check your Android Firefox about:support and about:config pages for your modified preferences, and see if the "_user.js.parrot" preference is showing success.

4) Finish

  • Disconnect: WebIDE menu|Runtime|Disconnect
  • For security, reverse settings you temporarily changed in any steps above:
    • Desktop Firefox's WebIDE preference back to false
    • Android Firefox's debugging off
    • Android's USB debugging off (if used)
    • Troubleshooting changes (desktop firewall, android firewall, router, etc)
@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Jan 20, 2018

@icpantsparti sweeeeet, that's awesome 💋 thanks for that. I'll get around to this sometime after FF58alpha user.js is released

@icpantsparti

This comment has been minimized.

Copy link

commented Jan 29, 2018

May be also worth a mention on a Android wiki page. You can view the prefs you have set on about:support, but if you want to get the contents of prefs.js on non-root Android.

Enter into the firefox url address bar: file:///data/data/org.mozilla.firefox (if using beta append _beta). Navigate your way through to the file inside your profile directory, such as: file:///data/data/org.mozilla.firefox/files/mozilla/????????.default/prefs.js

Tap on the prefs.js file and it displays, long press, select all, copy and paste into a text editor type app (such as QuickEdit, etc) for saving. (Note that firefox updates the prefs.js file on app exit so settings made during the current session would not be visible yet.)

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Jan 29, 2018

That's handy. Can't be arsed firing up FF on my phone, but you can also get a nice list via about:support > Important Modified Preferences

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Feb 12, 2018

https://github.com/ghacksuserjs/ghacks-user.js/wiki/1.6-Firefox-Android - first draft

ToDo:

  • add intro and also check that not all prefs are shown in android FF about:config
  • add rooted steps
  • add some pictures

PS: Many thanks to @icpantsparti and @TerkiKerel - there's only so much of me, so you'll have to share 💋 💋

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Feb 27, 2018

If anyone wants to provide some pics, proofread the wiki entry, or write up the tiny rooted section, then feel free

@jghq

This comment has been minimized.

Copy link

commented Mar 29, 2018

I am rooted but FF wouldn't pick up user.js for some reason. This method worked perfectly. THANK YOU.

Suggesting this for rooted:

All steps are performed on your Android.
*Bring up the list of running apps by tapping the usually square button and stop Firefox by swiping it away.
*Start your file manager that supports root, such as https://f-droid.org/packages/com.ghostsq.commander/.
*Copy your user.js file to your profile folder at data/data/org.mozilla.firefox/files/mozilla/[random_string].default.
*Set permissions on the file to match other files in the directory.
*Start Firefox, go to about:config and confirm user.js was recognized. Be sure to check the last line as well, in case processing was stopped in the middle due to some error.
*If you delete user.js from your profile directory, the applied settings will remain until you or the application changes them. If you don't delete the file, all settings in the file will be reapplied on each Firefox start.
*If no settings from user.js are applied, follow the Non-Rooted method below.

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Mar 29, 2018

@jghq Thanks for the feedback. I'll reopen this to remind me to write up the rooted section

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Apr 21, 2018

bump!

reminder to add the text re rooted devices and close this

@Thorin-Oakenpants

This comment has been minimized.

Copy link
Member

commented Apr 21, 2018

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.