DanilaFe / matrix-highlight

A decentralized and federated way of annotating the web based on Matrix.
Apache License 2.0
140 stars 3 forks source link

Firefox support #21

Open meain opened 2 years ago

meain commented 2 years ago

I was wondering what would the effort be to make this available in Firefox. Firefox currently does not support v3 manifest and I believe you are using a few v3 specific keys in the manifest. I am planning to put some time into getting this to work, but just wanted to check if you had done any research in this direction or if there was some specific reason why you went with v3 instead of v2.

DanilaFe commented 2 years ago

Hi! First of all, thanks for checking out Matrix Highlight, and for opening this issue. I haven't done too much research into Firefox at this time, but it is my primary browser too, and several people have already voiced a desire for running MHL on Firefox. Here are my thoughts on the feature summary, though:

  1. Background pages VS background services seems like the biggest change. However, I believe that services are actually more restrictive than background pages, so aside from some code changes, it's possible that things will work out of the box.
  2. MHL doesn't do network request modification.
  3. MHL works with manifest V3, which means it loads no external scripts already. Thus, it should still work on on V2.
  4. I use Chrome's promise-based APIs when possible. Firefox claims that it has this in the browser* namespace. Perhaps it won't be too bad to make everything play nicely, but I can imagine there will be some problems here.

It feels to me like the majority of work would be to cleanly make the two versions of the extension coexist in the same code base. In general, I don't know the state of the art of cross-browser development.

I went with Manifest V3 because Chrome is by far the most used browser, and manifest V3 is the "standard" way of making Chrome extensions at this moment.

DanilaFe commented 2 years ago

I'm going to give it a quick shot now, and see how far I can get.

DanilaFe commented 2 years ago

2022-01-22-220525_3073x2057_scrot Looks like it's not too terrible :)

meain commented 2 years ago

Damn, that was quick. Looking forward to using it on Firefox :)

DanilaFe commented 2 years ago

Me too! I'm keeping this open until I get it working on both at the same time cleanly.

Stvad commented 1 year ago

Hey there @DanilaFe I was wondering what is the status of the work/if you have your FF branch published somewhere? :)


UPD: oh somehow missed you're the author of the repo 😅. Found the branch!

Stvad commented 1 year ago

Also, the v3 is now enforced in Chrome =\ (if you want to publish the extension to the store, at least)

Stvad commented 1 year ago

As far as I can tell the current master in fact supports Firefox!

DanilaFe commented 1 year ago

Yes, master should support firefox, but V2 is no longer working in Chrome... As far as I can tell, neither V2 nor V3 works in both browsers. How frustrating!

Stvad commented 1 year ago

Yeah, it is quite frustrating. v2 still works in Chrome, you just can't publish it to the store =\

I here describe an approach of dealing with it for Parcel bundler: https://github.com/fregante/browser-extension-template/issues/78

DanilaFe commented 1 year ago

I've updated both to use manifest v3. The problem is that currently, Firefox especially loves tearing down background pages when they're "inactive" (even if they are active, it just immediately recreates them). This means that at present, the Matrix JS client is re-initialized every 30 seconds or so. If your account has slow syncs (i.e. if you're in a lot of large rooms), well, that will cause some trouble...

The proper solution is to persist the client data somewhere, so that the teardowns aren't as expensive. Even so, it's a huge pain that there's no way to keep a matrix client alive.

ptman commented 1 year ago

Sliding sync should be much faster. But I doubt any guarantees can be given as to how fast it should perform

Stvad commented 1 year ago

There is an option to run it in the content script. If you put it in the iframe it'll also run on a separate thread/process making sure it won't block rendering. I use such a simulated background page in https://github.com/transclude-me/extension/blob/main/source/content/background-simulation/utils.ts

DanilaFe commented 1 year ago

Thank you for the suggestion, @Stvad!

I was under the impression that content scripts can't do network requests, but maybe the iframe will help with that. Another problem is that I'd rather not create 30 matrix clients if a person has 30 tabs they're annotating. Also, unless each tab has its own "device" / login, there will certainly be race conditions when it comes to receiving syncs and generating transaction IDs for outgoing events.

DanilaFe commented 1 year ago

Sliding sync should be much faster. But I doubt any guarantees can be given as to how fast it should perform

I've been a bit out of the matrix ecosystem lately. Is sliding sync available to all, especially via the JS sdk? If so, combined with storing sync results and some other work, that might be the way to go (but older homeservers won't support it, right?)

Stvad commented 1 year ago

Content scripts def can send network requests, but servers may reject them, depending on the CORS configuration. That's not an issue in case of Matrix servers