Can I make a simple browser plugin for both desktop and mobile?

271 views Asked by At

I wanted to use Chrome but it looks like Chrome for Android can't run extensions? And support in Firefox seems shaky.

All I want is to request and execute remote CSS and JS files for a particular domain. I don't need any UI or anything.

Not sure if I should just forge ahead with Firefox or perhaps think about rolling my own 'browser' with plugin embedded?

1

There are 1 answers

8
gal007 On BEST ANSWER

You can use the Firefox SDK, available here: https://developer.mozilla.org/en-US/Add-ons/SDK

It allows you to develop for both platforms. And if you have troubles with sdk in firefox for android, you can read this: https://developer.mozilla.org/en-US/Firefox_for_Android

If no UI is required, it will be easy to set up :)

Regarding comments in this post, I made a script for setting up the under development extension:

# Run this script from your project base dir.
#1 - Complete the following vars:
#ANDROID_APP_ID=org.mozilla.fennec;
ANDROID_APP_ID=org.mozilla.firefox_beta; 
#ANDROID_APP_ID=org.mozilla.firefox;
APP_NAME="YourExtensionName";
OUTPUT_DIR=$HOME/Bureau;
FILES="./";
EXCLUDE="-xr!./.git";
CLEAN_APP_DATA=false;

#2 - This will clear all your app cache
if [ "$CLEAN_APP_DATA" == "true" ]; then
    adb shell pm clear $ANDROID_APP_ID
fi

#3 - This will create the XPI file
7z a -r $OUTPUT_DIR/$APP_NAME.xpi $FILES $EXCLUDE;

#4 - This will copy the XPI to the phone SD card. Don't worry if you don't have SD card, it will be copied to a directory called /sdcard
adb push $OUTPUT_DIR/$APP_NAME.xpi /sdcard/$APP_NAME.xpi;

#5 - This will start the Firefox App with the XPI to install
adb shell am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT -d file:///mnt/sdcard/$APP_NAME.xpi -n $ANDROID_APP_ID/.App;

#6 - Redirect tcp to watch via console
#adb forward tcp:6000 tcp:6000; #For Firefox for Android 34 and earlier
adb forward tcp:6000 localfilesystem:/data/data/$ANDROID_APP_ID/firefox-debugger-socket #For Firefox for Android 35 and later

#7 - This will wait to you to test your addon and press any key to close Firefox. 
echo ""; read -p "Press 'r' to restart or any other key to close the browser..." pressedKey;

if [ "$pressedKey" == "r" ]; then 
    adb shell am force-stop $ANDROID_APP_ID;

    #8 - This will remove the XPI from the filesystem (but it's still copied on your Firefox)
    adb shell rm /sdcard/$APP_NAME.xpi
    rm $OUTPUT_DIR/$APP_NAME.xpi;
    echo "Firefox has been forced to stop. Restarting...";
    adb shell am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT -n $ANDROID_APP_ID/.App;

    echo ""; read -p "Test your addon on mobile. Press any key to close app..."; 
fi

adb shell am force-stop $ANDROID_APP_ID;
adb shell rm /sdcard/$APP_NAME.xpi
rm $OUTPUT_DIR/$APP_NAME.xpi;
exit 0;