【问题标题】:Can I make a simple browser plugin for both desktop and mobile?我可以为桌面和移动设备制作一个简单的浏览器插件吗?
【发布时间】:2015-06-25 04:51:05
【问题描述】:

我想使用 Chrome,但 Android 版 Chrome 似乎无法运行扩展程序? Firefox 中的支持似乎不稳定。

我想要的只是为特定域请求和执行远程 CSS 和 JS 文件。我不需要任何 UI 或任何东西。

不确定我是否应该继续使用 Firefox,或者考虑推出我自己的嵌入插件的“浏览器”?

【问题讨论】:

标签: android google-chrome-extension firefox-addon desktop


【解决方案1】:

您可以使用 Firefox SDK,这里提供:https://developer.mozilla.org/en-US/Add-ons/SDK

它允许您为两个平台进行开发。如果你在 android 的 firefox 中遇到 sdk 的问题,你可以阅读这个:https://developer.mozilla.org/en-US/Firefox_for_Android

如果不需要 UI,设置起来很容易:)

关于这篇文章中的cmets,我做了一个脚本来设置正在开发的扩展:

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

【讨论】:

  • 很棒的解决方案。关于如何在开发过程中调试/测试插件的任何提示?通过usb连接android是否需要?如何从我的桌面文件夹推送/安装到 android 以进行快速测试?
  • @Noitidart cmets 对于这个回复来说太小了,所以我将它添加到答案中
  • @gal007 太棒了!我很期待,我将开始大力开发一些 FxOS 应用程序,这将对我有所帮助。
  • 嗨,我写了所有的脚本文件并制作了我的 xpi,但我不知道如何将我的插件从我的桌面下载到我的安卓上,我该怎么做?
  • 我想出了如何安装,而不是 adb 的漫长过程,我将我的扩展代码推送到 github,然后直接从 github 使用这个插件将它安装到 android 上:addons.mozilla.org/en-US/firefox/addon/… 这种方式是 wayyyy太麻烦他们要我安装整个 android sdk 废话:developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/…
猜你喜欢
  • 1970-01-01
  • 2013-06-09
  • 1970-01-01
  • 2011-12-28
  • 2011-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多