It's also recommended to use session storage for this. What about Redux? Well, I don't know how many of you are still using Redux, but a lot of you probably are, and you are familiar with it. Redux is not really possible in the silo setup of web extensions. There is a plugin, a WebExt Redux library, which stores the data in the storage, but it's using some proxies and messages to, basically, every time there is, like, a Redux action, it stores it in a storage, the same way as we are sending message with data. But it's not really recommended. It works, but sometimes serialization breaks the object references. It comes with a lot of performance issues. It's pretty hard to debug. The Redux dev tools don't work so well with this library, and it's just better to use the storage. Like, if you are architecting a new web extension, just be considerate about it.
Challenge number four is something that I ran into many times because I was not considerate enough, but now I am. CSS collision. Let's say you're injecting a little widget on the Open tab. I mentioned Grammarly, for example, but you know a lot of password managers also show little widgets on the pages, and you have very nice design for it, but the underlying website has their own way of, let's say, styling a button. Sometimes, you know, they have important styles, and you can't really override those with your own custom styles. So what is the solution? Well, you can also put important to all your styles and then have a very ugly style sheet, but there is a much better solution, which is using the Shadow DOM and custom web components to wrap your React bundle.
This comes for free in the WXT framework. Here is an example how you can do that. You're basically using the CreateShadowRoot UI, and where it's rendering, you just render it inside that. This comes with an isolation, so all the styles that are outside of your component, of your web component, will not be inherited by the web component, so you're starting fresh, which is really, really useful in most cases. Sometimes, of course, you don't want that, but I think 99% of the cases, you want your styles to be isolated from the underlying web page if you're injecting into it. Challenge number five is the communication between a web page, your web app, and the extension.
Comments