2

I would like to inject JavaScript into a website on a mobile browser (in this case on android). However, most mobile browsers do not seem to support any kind of plug-ins (except for Firefox, correct me if I am wrong).

Firefox support for mobile plugin development seems to be minimal too, for example one can not install xpi-files by downloading them (I have yet to find out how one can install a plugin that is not hosted on the add-ons for android site)

Why not use existing solutions?

The best way to inject javscript would be Greasemonkey but this is not supported on mobile. Scriptish supposedly is but I could not install it on any device. There are android browsers specifically written to support Greasemonkey scripts (Fat Ape or Tampermonkey or OilCan) but these are not used by many and while they enable JavaScript injection the lack in their support for other browser-features.

What exactly is my question?

My experience in Firefox-Plugin development is minimal so I would like to know: Is there something that would prevent something like this to run on FF-Mobile? Could it be done with other browsers too? I don't actually need the full power of Greasemonkey, injecting the same few lines into any website would probably do.

Community
  • 1
  • 1
Lukas Ruge
  • 2,204
  • 3
  • 30
  • 42
  • The linked technique is for FF *add-ons*. If you cannot install add-ons/extensions on your browser, you cannot use it. – Brock Adams Jun 06 '13 at 22:49
  • not sure what you are getting at. If it is the wording, I am using "plug-in", "add-on" and "extension" synonymous (there probably is a (more or less) subtle difference though, that I am just not aware of) – Lukas Ruge Jun 07 '13 at 06:41
  • You might want to take a look at the answers to this similar question: http://android.stackexchange.com/questions/1054/is-there-a-way-to-use-userscripts-greasemonkey-scripts-on-the-android-browser – Protector one Sep 05 '15 at 22:19

3 Answers3

2

Update 2

This again needs updating!

The new Firefox (current 95.2) no longer supports this method! But the old version still does! You will have to DL an old version (let's say 68.7). You can get it on ApkMirror. Then to install Greasmonkey either google it and choose the Mozilla page or just visit this link. On that page choose to download the file. When the XPI file will be downloaded it will automatically request to install it and that's it. You now have Greasemonkey installed on your Android device!

Be advised that this is an old unsupported Firefox version full of security holes!

Update

This needed updating! The new Firefox now has full support for Greasemonkey add-on!

Instructions:

  1. Find and install Firefox on the play store.

  2. Run it and from the menu choose Add-ons and install your favorite add-ons like the ad blocker uBlock origin. Use the search and input Greasemonkey and install it.

  3. Profit! :)

Old

  1. If you want full Greasemonkey with even cross domain / cross site GM_xmlhttpRequest support then your only option right now is: Opera Mobile Labs (with Extensions) (link to APK is on that site).

    Run Opera Mobile Labs app and visit Violent Monkey's extension site and install the 1.5.1.1 (OEX version) by clicking on "Add to Opera" and then choose "OK" (maybe you'll have to restart Opera Mobile for the extension to work.).

    To install an userscript you just need to load it in the browser by visiting the user.js URL location. If you have userscripts on your SD card, you can load them thru entering "file://" into the address bar and navigate to your user.js files and then choose "OK".

  2. If you have a bunch of normal scripts (no GM_ functions) then you could also use this instructions (it's faster!):

    • Save your user.js scripts in a folder on your SD card (eg. "/sdcard/js").
    • Run Opera Mobile app and enter "opera:config" into the address bar and then in the "Quick find" input enter "javascript". Go down and under "User Prefs" tick the following: "Always Load User Javascript" and "User Javascript". Under "User Javascript File" enter the path to the folder with your user.js files (eg. "/sdcard/js").
    • At the end don't forget to tap "Save" otherwise your setting will not be saved! Restart Opera!

    If you don't want to download the APK file then this second method also works with Opera Mobile Classic. You can find the app in the Play Store.

Yani2000
  • 854
  • 8
  • 11
0

If you can install Google Chrome (Android > 4.0) on your mobile phone you can do remote debugging.

Overview of Google Chrome for mobiles :https://developers.google.com/chrome/mobile/docs/overview

Overview of Remote Debugging: https://developers.google.com/chrome-developer-tools/docs/remote-debugging

Xavi
  • 196
  • 2
  • 9
  • But I can not write extensions for chrome mobile so I can not inject any JavaScript via this browser https://developers.google.com/chrome/mobile/docs/faq (however, the mobile debugging looks cool for website development) – Lukas Ruge Jun 06 '13 at 10:18
  • You can inject any javascript code manually on any website using chrome developing tools (https://developers.google.com/chrome-developer-tools/docs/console, it has a javascript console) anyway i dont know/understand whats the purpose of your application – Xavi Jun 06 '13 at 10:23
  • The purpose of the injected javascript would be to connect the website to an android application developed at my university, which has a javascript API. This has already been done using javascript that was provided with the webpage but then this code has to be put in by the provider of the website so it would be much nicer if it could be injected on load using a browser plug-in, allowing any website to be connected. – Lukas Ruge Jun 06 '13 at 10:29
  • 1
    Then i think this post may help you http://stackoverflow.com/questions/13535759/inject-a-javascript-api-on-everypage-loaded-on-webview if you're using a webview on your android app, if you plan using just a browser i have no clue :/ – Xavi Jun 06 '13 at 10:45
0

Another option for running Userscripts on mobile devices is the Tampermonkey userscript manager. There are Tampermonkey add-ons for both the Dolphin and UC Android browsers.

Tampermonkey add-on for the Dolphin Web Browser: https://play.google.com/store/apps/details?id=net.tampermonkey.dolphin

Tampermonkey add-on for the UC Web Browser https://play.google.com/store/apps/details?id=net.tampermonkey.uc

To use them you first need to have the respective browser installed.

user280109
  • 1,476
  • 3
  • 16
  • 27