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

2.1.4版在Firefox Android上option.html出現空白頁因而未能啟用 #48

Open
SakuraiNaomi opened this issue Dec 22, 2021 · 11 comments
Labels
Android bug Something isn't working

Comments

@SakuraiNaomi
Copy link

Firefox Android 68.11
Firefox Android Nightly 83.0a1 和 97.0a1
都相同情况,頁面只看見半秒就轉成全白不能選自動轉換
68.11最後一版不像Nighly加Collection必定只能加入最新2.1.4
放回同文1.5頁面就正常出來了

有爬過一會Closed issue知道作者繁忙,但是68已經有好些網站
不能正常運作,也花了一周沒找到好的替代方案... 祝聖誕快樂 :D

Screenshot_20211220-125907

@t7yang
Copy link
Contributor

t7yang commented Jan 30, 2022

是說,如果用 1.5 版本就完全可以正常運作嗎?

@SakuraiNaomi
Copy link
Author

因為我只有用自動轉換,bbs網站上的簡體字的確有轉換成繁體字,
其他功能不敢保證正常,68.11裝上1.5同一頁面這樣子才能啓動

Screenshot_20220207-192930

@t7yang
Copy link
Contributor

t7yang commented Mar 4, 2022

你的 BBS 是指 term.ptt 還是純網頁。因為敘述看起來我不是很容易理解。
或是方便的話,請你稍微一小段影片展示兩個版本之間的差異,這樣比較觀察你碰到的是什麼問題。
目前 Github 已經支援上傳影片。

@SakuraiNaomi
Copy link
Author

3dots > Addon > Addon Manager > 新同文堂 > 設定
2.1.4版白色頁面無法選擇自動轉換以啟動同文堂功能
1.5版正常

20220306_020218.mp4

@t7yang t7yang added bug Something isn't working Android labels Apr 9, 2022
@t7yang
Copy link
Contributor

t7yang commented Apr 9, 2022

不確實是不是用了新語法導致錯誤,還需要再詳細研究。

@htbkoo
Copy link

htbkoo commented Oct 2, 2022

(不好意思, 在 GitHub 上面我比較習慣使用英文 - 如果有寫不清楚的地方, 我可以再用中文說明)

TL;DR

I tried to fix the extension with these changes - not sure if these are the proper fixes we need, but at least on my phone the option page would not crash, and the auto-translation (from simplified Chinese to traditional Chinese) now works:

htbkoo/tongwentang-extension@master...htbkoo:tongwentang-extension:fix-android-fenix

Caveats

  1. As discussed below, Firefox on Android does not support contextMenus / commands. So, I am afraid that they would not work on mobile phones, but I am not sure how we should handle that either.

Environment

  • Extension version: New TongWenTang 2.1.6
  • Browser version: Firefox Nightly (107.0a1)
  • Device: Google Pixel 6
  • OS: Android 13

More details

I had tried to debug the extension with Firefox Nightly based on this instruction and I had found that there are few errors preventing the extension from working on Android

I. There is an error Uncaught TypeError: can't access property "autoConvert", n is undefined. when opening the option page

Issue

After some investigation, I think the error is thrown from here (GeneralSettings.tsx#L16) and general is undefined.

I am suspecting that the general object got overwritten to undefined here (use-general-opt.ts#L38) when the effect hook try to read the value from storage when the storage is empty (please correct me if I am wrong).

Fix attempt

I think we can probably fix this by either:

  1. using optional chaining at <GeneralSettings /> (please see this for details: https://github.com/htbkoo/tongwentang-extension/compare/master...htbkoo:tongwentang-extension:fix-android-fenix-check-before-setting-value?expand=1)
  2. avoid setting the value to general at use-general-opt.ts if the value is undefined (please see this for details: htbkoo/tongwentang-extension@master...htbkoo:tongwentang-extension:fix-android-fenix-optional-chaining)

II. The Context Menu option page and Word option page failed to load

Issue

Unfortunately, the Context Menu option page and Word option page also failed to load.

Fix attempt

Similarly, I had tried to fix them by avoid setting the value if the value is undefined (Please see this commit for details: htbkoo@e3bf1e5)

III. Background script failed to run due to some unsupported functions on Android

Issue

After applying the above fixes, the option page would work but the translation still failed to run.

And I found that it is because the background script did not successfully run because some of the features (e.g. contextMenus; commands) are unsupported on Android Firefox and some functions are undefined (e.g. commands.onCommand; browser.contextMenus.create; browser.contextMenus.remove).

FYI, this is also hinted by the warnings by Firefox that some of the fields in manifest.json (e.g. permissions.contextMenus; commands) are unsupported

Fix attempt

I ended up trying to fix the issue by adding optional chaining for all offending usages. (Please see this for details: htbkoo/tongwentang-extension@fix-android-fenix-other-options-pages-error...htbkoo:tongwentang-extension:fix-android-fenix-background-script)

IV. tabs.detectLanguage is not a function

Issue

This is quite strange but somehow tabs.detectLanguage is undefined on my Firefox and that was the last obstacle that blocked the extension from working.

Fix attempt

In order to fix the issue, I added a try-catch around the usage and similarly defaulted the language to ZhType.und when there is any error caught (Please refer to this commit for details: htbkoo@973f7d7)


Please let me know if you need more information.

Thank you!

@htbkoo
Copy link

htbkoo commented Oct 6, 2022

Just another small updates for your information:

I ended up switching to use the Kiwi Browser (kiwibrowser/src) instead.

And the extension just works out of the box (note that Kiwi Broswer provides native support for extensions).

So I guess the issues are exclusive for Fenix on Android. 🤔

@t7yang
Copy link
Contributor

t7yang commented Oct 9, 2022

first of all, thank you so much for giving such helpful and detail debug information 🙏

I think they removed the contextMenu completely from the mobile (I checked the MDN, can't find the contextMenu anymore...)
also, the mobile browser has very limited APIs

using the contextMenu instead of menu is for better compatibility (chromium based browser do not support it, but I think they do now)

I.
I think the error is because the mobile doesn't support the sync storage, so end up the extension got the undefined.

II.
if the chromium based browser did support the menu APIthen I think replace thecontextMenuwithmenu` can resolve many error.

III.
we can skip the command setup if the runtime is mobile.

IV.
same, we can skip the lang detect if the runtime is mobile.

you information is helpful, I think we can solve the problems accurately. (adding optional chaining make the code smell, I don't think sweep the errors under the carpet is a good idea lol)

@null-von-sushi
Copy link

Has there been any progress on this? I'd love to switch to Firefox but am stuck on Kiwi as it's the only way for me to use this extension.

Even if the extension settings page isn't fixed to work on mobile, I would still be happy to at least know if a workaround to set the auto-convert mode on

t7yang added a commit that referenced this issue Sep 1, 2024
- deprecate the namespace approach
- the some APIs optional in order to force us to check before use
@t7yang
Copy link
Contributor

t7yang commented Sep 9, 2024

hi @null-von-sushi
the current target is MV3 migration.
will take a look after the migration.

@null-von-sushi
Copy link

null-von-sushi commented Oct 3, 2024

In the meantime, is it possible to install the 1.5 version on current Firefox (Android)? I cannot seem to find the 1.5 version anywhere

EDIT: I figured it out. It's convoluted, but there's a way.
First install an old version of firefox such as v. 68.7 (I used Firefox Beta, downloaded from APK Mirror).
Then install the 1.5 version of New Tong Wen Tang extension from addons.mozilla.org. Just download the file and open it with Firefox. I used 'Material Files' from F-Droid to 'open with' the file (as filetype 'other'), then select Firefox.
After that you can update FF and the extension will keep installed.

credits for figuring out how to install old extensions go to this reddit post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants