Migrating ChromeOS IME to manifest V3

195 views
Skip to first unread message

Imperishable Night

unread,
Mar 16, 2022, 10:08:31 AM3/16/22
to Chromium Extensions
I'm currently developing a ChromeOS IME (https://github.com/bbbbbbbbba/my-ime2) when I am informed that manifest V2 is phasing out and I need to replace my background page with a service worker. From what I've read this means I need to handle each event separately and use storage APIs to store state information. Since an IME is inherently stateful (at least while inputting), I'm worried that storing all the state information can get quite hairy. I'm also worried about performance and response time issues since the storage APIs are asynchronous.

Can someone provide any guidance or examples on how to migrate IMEs to manifest V3?

wOxxOm

unread,
Mar 17, 2022, 10:18:23 AM3/17/22
to Chromium Extensions, mprsh...@gmail.com
Assuming the state is JSON-serializable and isn't very big, the asynchronous access to the storage would be a problem only in events where you want to return a value synchronously, but you should be fine because onKeyEvent allows asynchronous response per the documentation. You can keep the state in chrome.storage.session to avoid it being written to the disk, max overall size is 1MB.

The biggest problem would be the time to start the service worker (at least 50ms plus the time to start the scripts), but it's probably acceptable when typing. If not, you'll have to prolong the service worker's lifetime artificially.

Imperishable Night

unread,
Mar 17, 2022, 2:43:35 PM3/17/22
to Chromium Extensions, wOxxOm, Imperishable Night
Using chrome.storage.session sounds like a step in the right direction, although I cannot find it in the documentation, so I'm not sure if there is any "catch" about it.

The biggest challenge is probably determining exactly what state information I'd need to store since it's scattered in multiple modules. I forked the project from another developer (who currently doesn't seem to be active) so I don't fully understand the code logic.

Simeon Vincent

unread,
Mar 22, 2022, 3:09:44 AM3/22/22
to Imperishable Night, Chromium Extensions, wOxxOm
... although I cannot find it in the documentation, so I'm not sure if there is any "catch" about it.

Beyond the size limit there shouldn't be any catches. API-wise it's basically just another StorageArea on the Storage API.  The only reason it's not currently exposed in our docs is that itdue to a bug in our documentation build system.

Simeon - @dotproto
Chrome Extensions DevRel


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/e28e4fe4-74e0-4121-9765-559dfdb5ceddn%40chromium.org.

Imperishable Night

unread,
Sep 1, 2022, 11:24:13 PM9/1/22
to Chromium Extensions, wOxxOm, Imperishable Night
After half a year I've just got around to doing this :( I'm currently worried that if I am to handle all the events asynchronously, some race conditions may be possible. For example, if I get two key events in quick succession, and both needs to wait for the IME to load asynchronously, I'm worried that I might end up handling them in the wrong order. Can someone familiar with asynchronous JS reassure me?
在2022年3月17日星期四 UTC-7 07:18:23<wOxxOm> 写道:

Imperishable Night

unread,
Dec 1, 2022, 6:06:48 AM12/1/22
to Chromium Extensions, wOxxOm, Imperishable Night
I just tried running my IME with manifest V3 (even though I haven't fully implemented state serialization) and found something discouraging. What I did was:

1. Open chrome://extensions so that I can see the status of my service worker.
2. Try my IME in the address bar (the same thing happens when I use a text editor). It works fine.
3. Wait a while (without actively using the IME) until my service worker goes inactive.
4. Try to input again. The service worker remains inactive and whatever letters I enter goes directly to the address bar.
* In some of my tests, the service worker did go active, but only after I enter the first letter (i.e. first letter went to the address bar and the next ones went to the IME). I couldn't find a pattern on when this happens.

If the service worker had gone active but the IME hadn't worked, then it would probably have been because I didn't properly load the IME state, and I could work on that. But since the service worker didn't go active at all (i.e. it seems that it didn't receive the key event even though I did chrome.input.ime.onKeyEvent.addListener(...) at the top level), I'm not sure if I could do anything about that. Moving to another text area, or deactivating and reactivating the IME, does let the service worker go active, but having to do that every time I ponder for a while with my text editor open is obviously unacceptable user experience.

I have pushed my current (expected to fail, but not failing in the expected way) code to GitHub (https://github.com/bbbbbbbbba/my-ime2/commit/7d120a351287ec64723f2982a7dc563fb92b10c9). If I have made any mistakes in modifying manifest.json, please let me know.
在2022年3月17日星期四 UTC-7 07:18:23<wOxxOm> 写道:

wOxxOm

unread,
Dec 1, 2022, 6:24:53 AM12/1/22
to Chromium Extensions, mprsh...@gmail.com, wOxxOm
It's a bug in Chrome. Try uninstalling the extension, then install it again.

Imperishable Night

unread,
Dec 1, 2022, 6:38:58 AM12/1/22
to Chromium Extensions, wOxxOm, Imperishable Night
Unfortunately that doesn't seem to be it. And I'm pretty sure I did just uninstall and reinstall the extension because in my hurry to do that I've lost my self-learned dictionary :( (Fortunately I have a backup, even though it isn't exactly up-to-date.)

Imperishable Night

unread,
Dec 1, 2022, 6:47:28 AM12/1/22
to Chromium Extensions, wOxxOm, Imperishable Night
Something I'm considering is that with chrome.input.ime.onKeyEvent, "the event will be sent to the extension if this extension owns the active IME." I'm not sure how the operating system determines whether my extension owns the active IME, so maybe that for some reason doesn't work when the service worker is inactive?

在2022年12月1日星期四 UTC-8 03:24:53<wOxxOm> 写道:

Jackie Han

unread,
Dec 1, 2022, 7:10:46 AM12/1/22
to Imperishable Night, Chromium Extensions, wOxxOm
Looks like a bug, if it works in MV2, but doesn't work in MV3. Since there are very few developers using this API, I guess no one has reported bugs in this area yet. I suggest you report bug.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

Imperishable Night

unread,
Dec 1, 2022, 8:03:48 AM12/1/22
to Chromium Extensions, Jackie Han, Chromium Extensions, wOxxOm, Imperishable Night
Turns out that there is an existing bug report, which I have just starred. Hopefully Chrome people gets around to fixing it.

Although truth to be told, the entirety of the IME API feels really unwieldy. I have no idea why I have to keep track of contextID myself, and having to implement basic functionalities like turning pages also makes it unnecessarily difficult to start. I also don't know how to make my custom IME work well with the touch screen.

Reply all
Reply to author
Forward
0 new messages