5

Is there a way to inject (non-malicious) JavaScript (or CSS) statements into Chrome on Android whenever a matching URL is loaded?

Basically, I'd like to modify how some sites look.

One example would be m.facebook.com:
I'd like to inject something like:

#header: {position:fixed; margin-top:-2px}
#root:{margin-top:40px}

Unfortunately, Google doesn't extend the plugins API for the mobile platform!

Any thoughts?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Ayman Nedjmeddine
  • 11,521
  • 1
  • 20
  • 31
  • 1
    There's no straightforward way since [plug-ins are not supported on mobile](https://support.google.com/chrome/answer/2710225?hl=en). A few ideas: use a proxy that you own and edit the traffic on the fly not recommended security wise. [Build your own browser from source and edit as you wish](http://stackoverflow.com/questions/27059494/source-code-of-google-chrome-android-app) which is a hassle to do. – HamZa Jul 18 '16 at 22:25
  • @HamZa, routing traffic through a proxy is not an option in my case, unfortunately, but I like the idea. Thanks! – Ayman Nedjmeddine Jul 19 '16 at 07:56
  • See also https://stackoverflow.com/a/21612566/32453 for injecting – rogerdpack Aug 01 '17 at 20:14

1 Answers1

2

See how to create a bookmarklet, create one and put your JS code to it.

Example of the code:

javascript:(function(e){e.setAttribute("src","JS-URL-to-inject");document.getElementsByTagName("body")[0].appendChild(e);})(document.createElement("script"));void(0);

To execute the bookmarklet, follow instructions in the above link 1.

Tommy
  • 123
  • 5