themoeway / yomitan

Japanese pop-up dictionary browser extension. Successor to Yomichan.
https://chromewebstore.google.com/detail/yomitan/likgccmbimhjbgkjambclfkhldnlhbnn
GNU General Public License v3.0
977 stars 74 forks source link

Support for Safari? #66

Open themoeway-bot opened 1 year ago

themoeway-bot commented 1 year ago

rjbiii opened issue FooSoft/yomichan#986 on 2020-11-03


With recent updates to Safari, it's easier to port extensions to the browser. Are there any plans on porting yomichan to Safari?

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2020-11-07


I don't have plans for it currently, but that's not to say it can't be done; I don't really have a testing environment for it currently. It may still be up to @FooSoft to decide if he wants to do anything with that.

themoeway-bot commented 1 year ago

FooSoft commented on 2020-11-07


Has Safari switched to the same Web Extension model as Chrome and Firefox? Last time I looked at it several years ago, it was very different, and would require many changes to the code.

I don't really see anything happening for Safari, honestly. It would be an additional development burden, and would steal @toasted-nutbread away from doing all his amazing work for Chrome and Firefox (which together cover the vast majority of the user base) 🙂

themoeway-bot commented 1 year ago

okuRaku commented on 2021-03-23


Hi, just passing through to say I recently discovered Yomichan (had used rikaichan/kun for decades) and would love to see Safari support. Safari (especially on M1 macs) is seeming to be the best choice for browser for Mac users. Searching around (especially reddit) I found several other users like myself wanting to stick with Safari but looking for some Yomichan alternative. Of course, I have no idea what the complexity is to do so (now I'm curious myself). Of course one consideration is MacOS/iOS has the native dictionary/Lookup feature which some compromise for (I myself use it constantly on iOS apps for readings).

Love the app and the incredible work you've all done to expand and support it! Cheers!

edit: Well, I tried the Apple-provided Web Extension converter and it did not "Just Work" sadly. It did mostly look correct but couldn't get the popup to display. There were several warnings running the tool, probably one of these really is crucial I suppose (or something else, who knows...)

Warning: The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari:
    clipboardRead
    persistent
    webRequestBlocking
    match_about_blank
    sandbox
themoeway-bot commented 1 year ago

toasted-nutbread commented on 2021-03-28


Noted, I'll try to look into seeing how compatible Yomichan is with Safari's web extension implementation.

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2021-04-17


I've done some initial investigation into supporting Safari, and my current take-away is that their implementation of Web Extensions has some bugs which cause Yomichan to not work correctly. This is not to say it is entirely impossible, but it would take some reworking of Yomichan's internals for it to work properly, which is unfortunate, since it's an issue only for Safari.

https://stackoverflow.com/questions/65058757/sendmessage-not-received-by-options-page-onmessage-in-safari https://developer.apple.com/forums/thread/668098

themoeway-bot commented 1 year ago

kavinvin commented on 2021-06-21


@toasted-nutbread I've roughly tested a speculation of the bug on sending/listening messages in Safari.

At least, chrome.runtime.sendMessage seems to work fine and can be received by chrome.runtime.onMessage.addListener in Yomichan.

The search function seems to be perfectly fine either as I can log the dictionary entries. The problem occurred when creating a popup. Promise from https://www.github.com/FooSoft/yomichan/blob/0556c503195fb274069817514ceaad9ed2f1c998/ext/js/app/popup.js#L286 seems to be unresolvable and stuck on await. Thus, the popup can't be displayed.

Edit: I'm using Xcode 13 Beta to convert and build the extension. Not sure if that makes difference.

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2021-06-21


It's been a few months since I tested, but I was definitely having issues with sendMessage actually being received in certain contexts. I believe the messages weren't being received by extension pages, but were being received by content scripts. For example, opening the settings page would usually not be respond since the initial await yomichan.prepare(); would not finish.

I believe that is part of what was causing frameClient.connect to not resolve; its implementation is relatively complex, so that could be one of multiple problems as well.

I was testing in a VM, so maybe that's part of the issue, I'm not sure.

themoeway-bot commented 1 year ago

kavinvin commented on 2021-06-22


@toasted-nutbread Ah, yeah, it really stuck at await yomichan.prepare(). Therefore, yomichan.api.broadcastTab('frameEndpointReady', {secret: this._secret}); cannot be reached. That's why frameEndpointReady action never executed, so does frameEndpointConnected. Thus, the promise is never resolved.

I'm not sure what is the problem in async prepare(isBackground=false), but it somehow seems to stuck at https://www.github.com/FooSoft/yomichan/blob/0556c503195fb274069817514ceaad9ed2f1c998/ext/js/yomichan.js#L104 despite that the Promise should already resolved by https://www.github.com/FooSoft/yomichan/blob/0556c503195fb274069817514ceaad9ed2f1c998/ext/js/yomichan.js#L174

themoeway-bot commented 1 year ago

kavinvin commented on 2021-06-22


I'm only guessing, but the existing problem is deemed to be the top of the iceberg? Not really sure how many problems actually exists.

I know that Yomichan is much more complex, but Safarikai might be a similar example that's working well in Safari. With html injection method is somehow similar? One of the difference is that they use safari.extension.dispatchMessage to communicate with Swift backend.

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2021-06-22


The problem isn't so much that the issue can't be worked around; it could be addressed with some effort to replace chrome.runtime.sendMessage with messaging ports, although that comes with its own set of problems.

However, the issue still seems to ultimately reside on Safari's end, where it just doesn't send the messages properly. Clicking the extension button would usually result in messages getting through (e.g. the search page would sometimes start responding after clicking that button). This seems similar to the activeTab permission, but realistically that should not be affecting the extension the way that it is.

themoeway-bot commented 1 year ago

xrishox commented on 2022-05-28


it would be nice to get safari support. one perk would be that it would make it available on iphone and ipad as well.

themoeway-bot commented 1 year ago

xrishox commented on 2022-05-29


would you guys be willing to accept paid sponsorship to implement safari, but more specifically ios/ipad os support? @FooSoft @toasted-nutbread

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2022-05-30


The comments below are solely my own and I do not speak on behalf of any other Yomichan contributors:

This gets into the sponsorship question raised in #2123, so I have a brief response in there. Specifically for this issue, the issues are more of the following:

themoeway-bot commented 1 year ago

xrishox commented on 2022-05-30


I understand your hesitation and won't push any further than this comment. The long term maintenance burden was something I hadn't considered. It also makes sense not wanting to turn something that is a fun open source side project that you are working on into being something you become obligated to work on. Also logistics complicating things is problematic for sure.

It's definitely not my goal to earn any particular special priority or favor in general outside of what I would be directly sponsoring. I could pay for an ipad mini, the developer account and would be willing to pay for your time as well depending on how long you would think it would take and what you would think a fair hourly wage would be. If your privacy is important I could pay in bitcoin.

if for some reason you change your mind then you can reach out, assuming its something I'm still needing. totally no pressure at all though.

themoeway-bot commented 1 year ago

FooSoft commented on 2022-05-30


@xrishox, I've taken a back seat on Yomichan development; the number of projects I maintain has increased but the amount of time I have overall has decreased... @toasted-nutbread has been doing an amazing job running things; support from other contributors has also been invaluable in keeping this project alive.

OSS development is really a labor of love, and I strongly believe that the primary purpose of any project is to meet the developer's needs. The moment that you start implementing features or supporting a project that you no longer actively rely on, it becomes a job. Sponsorship can help act as a way of saying "thanks for what you do", but at the same time it can contribute to a feeling of obligation. As pointed out it, things become even weirder when you consider that there exist many contributors who helped make the project be what it is today. It's complicated enough just to think about what happens with licensing, without bringing financials into it.

Hardware, accounts, and ongoing technical burden of validating that the extension does not break due to browser changes is a whole other issue. The last one is especially big; even if someone were to do a drive by PR with all of the Safari stuff implemented you could end up at a net loss if you don't personally have any skin in the Apple ecosystem but still have to keep it alive.

This is all very similar to the reason that Yomichan would never support any language outside of Japanese. If someone were to add Chinese support, does it mean that toasted or myself would have to learn Chinese just to maintain the project?

themoeway-bot commented 1 year ago

xrishox commented on 2022-05-30


totally fair points. thanks for all that you guys have done and i totally understand!

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2022-06-01


Some more testing on Safari reveals that its support for extensions is still not on par with Firefox or Chrome. It doesn't seem to be able to embed <iframe> elements using an extension URL.

Blocked a frame with origin "https://jisho.org" from accessing a frame with origin "safari-web-extension://aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa".  The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "safari-web-extension". Protocols must match.

And the other issue that I previously encountered of the settings page not loading properly still exists.

themoeway-bot commented 1 year ago

landonepps commented on 2022-06-22


Here's a Rikaikun fork for Safari if you'd like a reference for working around Safari's quirks: https://www.github.com/birchill/10ten-ja-reader (It's a great extension in its own right, but there's no epwing support.)

And thanks for all your work trying to get this ported to Safari!

themoeway-bot commented 1 year ago

toasted-nutbread commented on 2022-06-22


I've messed around with some of these extensions before, and the Rikai* extensions probably have an easier time since they don't deal with <iframe> shenanigans in the same way that Yomichan does, and that is the current issue which prevents Yomichan from working on Safari unfortunately.

foxmean commented 6 months ago

Orion browser should be a little bit easier to support? At least they tried to 'porting hundreds of APIs' from Web Extensions API. This browser is using WebKit engine (same one used in Safari). So it should be really fast on Apple silicon machine. I tested Yomitan of both Chrome & Firefox versions on this browser myself. The pop-up didn't work, as expected. However, the Yomitan search page worked! So, you can litterally use Yomitan in the browser. Unfortunately, Anki connect still didn't work and it is very crucial for me because I need it to pull Forvo's speech via Yomichan Forvo Server plugin that need AnkiConnect plugin to communicated with Yomitan in the browser. And most importantly, it still cannot add Anki card. Hope Orion team can do about it. But I will leave error code here in case if Yomitan team can handle something from your side.

{
    "action": "version",
    "status": 403
}

@chrome-extension://likgccmbimhjbgkjambclfkhldnlhbnn/js/comm/anki-connect.js:320:36
Kuuuube commented 2 months ago

Apparently disabling Use secure popup frame URL and maybe Use a secure container around popups as well in the advanced options under Security could make the popup function in Orion. I don't have an apple device to test this, if anyone is able to and can confirm whether this works or not that would be great.

foxmean commented 2 months ago

Apparently disabling Use secure popup frame URL and maybe Use a secure container around popups as well in the advanced options under Security could make the popup function in Orion. I don't have an apple device to test this, if anyone is able to and can confirm whether this works or not that would be great.

Disabled both options and still doesn't work for me.

jamesmaa commented 2 months ago

Has anyone tried this method? https://developer.apple.com/documentation/safariservices/safari_web_extensions/converting_a_web_extension_for_safari/

ellieglad commented 2 months ago

Original comment in #949

Attempted to do this, following the documentation, and the results are the same as in #66 . Noted issues: Yomitan seems to correctly scan the text, but the results popover is not appearing, despite disabling both Use a secure container around popups and Use secure popup frame URL.

Enable background clipboard text monitoring is also not permitted to be enabled, this might be due to having to grant new entitlements after converting to a safari web extension.

I could also not get the import dictionary collection option to work, as it hung partway into importing. Importing a few individual dictionaries seemed to work, though I did not check if it also started hanging after a certain amount of dictionaries were imported.

My expectation is that some of this is tied up in how safari/apple entitlements work and some things that would require a deeper look or adjustments.

Some additional details from the conversion command:
Running macOS sonoma 14.4.1

App Name: Yomitan
App Bundle Identifier: com.yourCompany.Yomitan
Platform: All
Language: Swift
Warning: The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari:
    clipboardRead
    match_about_blank
    offscreen
    type
    sandbox
    open_in_tab