Writing an extension for Opera and Chrome: A look at the process
As many of you remember some time ago, Google hid the link to the Reader for the second time, replacing it with a link to the Photos. The first time this caused a wave of user dissatisfaction and Google returned everything back, citing an error. Then, immediately, an extension for Chrome appeared, returning a link to the Reader. I ported this extension for Opera.
When the second time Google transferred the link, the wave of indignation was already not so strong. At first, it even seemed to me that no one paid attention. The community was busy with more important news. But there was a discussion on the Google support forum and even an official responsethat Google is always striving to improve its products, and such an improvement may lead to actions similar to what happened with reference to the Reader. I remembered my extension, uncovered the dusty code and decided to make the extension more enjoyable and more meaningful. Namely, to give the user the opportunity to set the link structure himself. The extension should dynamically pull out all links from the page, show them to the user in the form of two columns and allow them to be dragged with the mouse. It turned out that there was no such extension for Chrome either, and additionally I got the idea to write two extensions with common code.
The extension architecture is similar in both browsers. It is conditionally possible to divide the inside of the extension into what works in the context of the page you are viewing and what works in the browser context. Why is it important to separate these concepts? Because scripts embedded on the page have a more stringent security policy. For example, I could not connect a third-party script. The jQuery library acts as such a third-party script. At the same time, a script that works in the context of the browser connects anything without problems. For more specifics, let's call scripts by their names: the background process works in the context of the browser, the built-in process in the context of the page.
The interaction between the background and embedded scripts takes place via messages. You need to hang up message handlers both there and there. Implementation details were already reported on Habré.
If we talk about the code, we can highlight several interesting points:
- Debugging difficulties. Sometimes the extension simply stopped working, there was nothing in the log. Then it turned out that somewhere there was a syntax error and everything was quietly dying. It happened to me 1 or 2 times. I could not artificially reproduce such an error, and in the logs I always received an indication of the place of the syntax error.
- You can do everything according to the documentation, and then it turns out that messages are not sent. If the main functionality of the extension is tied to messages, then it stops working. In the log, of course, no information is displayed. This led to the fact that at some point I started abundantly covering my code with debugging messages so that I could trace where the script control still gets and where it doesn't.
- In my opinion, internationalization is made better in Chrome than in Opera. The opera follows the W3C recommendations regarding widgets and offers to create a separate folder for each supported language with a full copy of the extension translated into the desired language. I see the problem here is that when you need to slightly correct the layout in one of the files, you will have to do this in all copies of this file. Chrome stores only text messages in different folders and allows you to access them by identifier.
- In the file with extension metadata (
config.xmlfor Opera and
manifest.jsonfor Chrome), you can allow access to other sites. In Opera, you need to be careful with slashes. Instead, for example,
you need to write.
In the first version, the extension does not gain access to the specified page.
- In Chrome, for the embedded script, you can specify the pages on which it should be run, directly from the manifest. At the same time, generalization characters are supported. For example, for a script to work on all pages of a domain
google.com, you can write
. But you cannot write a
script to work on any domain with a word
Technical documentation and related materials
Opera and Google differ slightly in terms of developer assistance. Both companies provide detailed documentation, videos, and examples. Subjectively, it’s harder for me to read Google’s documentation. They are very fond of hyper-links and reading turns into a leapfrog: I read a paragraph, followed a link, read a paragraph, followed either a new link or back. Separate quest from Google: try to go to the documentation page and find recommendations for publishing the extension. Google is increasingly focused on applications, not extensions. Background information for the publication process is located on the application development pages .
The Opera did a great thing - templates for creating icons. Templates can be used in Photoshop or Inskape. I am far from design and it took me some time to master this template, but then I appreciated it. It is really easier to create icons of the right size with it.
Chrome Web Store and Opera Extensions
|Localization and description of the extension||Invites the developer to fill out a description in all localization languages, showing the input fields one by one||Shows only one input field. Switching to another language occurs using combo box. I did not immediately find this combo box and thought that for some reason I could enter a description only in the default language|
|Screenshots||There is only one size requirement - screenshots must be less than 800x600 pixels||They suggest taking screenshots of a fixed size of 1280x800 pixels. Additionally, they offer to make several advertising images. Extensions without ad images receive less attention in search results|
|Visibility of expansion||There is a section - new arrivals. Through it, people can somehow find out about new products or updates. I think that my extension was noticed precisely because of this section.||There is no information about new extensions. The published extension immediately falls into the general boiler and through the official catalog it is very difficult to find|
Google is gradually accustoming us to the uselessness of URLs. Surely there are people who go to facebook, typing facebook in the search and following the link. Why do we need an address to remember, if there is Google, which remembers everything for us ?! As a result, extensions in the Chrome directory have great view identifiers
jlmhhcdodlafcgaopokedcaejpbiagkk. Try reading the text and meeting two links
chrome.google.com/webstore/detail/iiamfmleocemmjdnbfifnmdgekeokakhunderstand which link refers to which extension. Opera creates a link based on the name of the extension.
People do not read already written comments before posting theirs. Actually, this is not news for any blogger, but nonetheless. Get the same thread on the Google forum. It consists of 99% of the messages "return back the link to the Reader." In this thread, I left a link to my extension. Nobody seemed to notice her. Everyone continued to write angrily about the return of the link. Someone even released another such extension (just swapping links) and also wrote about it in the thread. A small discovery was how one person really liked my extension, and he went and wrote about it all on the same google forum and gave a link. His message, unlike mine, was not left without attention.
In the Opera several times people wrote that they give a rating of 3 or 4 because of this and because of this, and they missed with a mouse and actually set 2. This is, firstly, a question of usability. Perhaps such a rating as on Habré (plus and minus) would be more understandable. Secondly, you do not get a rating that would make your extension more visible to users. Thirdly, if you tend to worry very much about the rating, then your emotions will increase.
I was very surprised by the approach to statistics from the search giant. A number is available to the developer called "number of users per week." This figure speaks little to me. The tightened statistics of Google analytics helped to understand that they still use my extension in Chrome. Opera, however, shows an easily understandable figure - the number of downloads. With this figure, I will not need additional statistics to understand the relevance of expansion. But in both browsers, I don’t know anything about those who probably installed the extension for themselves, and then deleted it. So, in general, I would like more informative regular statistics from both browsers.
I screwed two buttons for donations: from PayPal and Yandex.Money. By the time the second version was published, I received exactly zero donations. I can’t say that I was very surprised. As you know, very few projects can raise donations. I wanted to make the second version of the extension conditionally paid: full functionality would appear 10 days after installation. If someone wanted before, then you would have to pay some symbolic amount. I was stopped by several things (I do not have a legal entity). The first is the lack of adequate payment systems for non-residents of the United States. Only Paypal was found, in which I have an account in euros. According to statistics, I saw that the majority of users of the Chrome version of the extension are from the United States. I was not sure that they would be willing to pay 1 euro for the extension and another one and a half for the associated costs. Moreover,
The second is ethical considerations. I have nothing to do with Google, so why should I parasitize on it, even spending my own time ?! I have gained experience, and it’s better to make money on something that will be completely mine.
Chrome supports auto-updating of versions, but if you changed the list of necessary permissions in the new version, then auto-updating is disabled. The user will have to find out for himself that a new version has been released and press the “Update all installed extensions” button himself. In Opera, the situation is similar. After changing the access rights in the manifest, messages about the new version did not come.
- Writing cross-browser extensions is very possible and in fact not so difficult.
- Extensions are supposed to be free. If you suddenly want to make a profit, then the browser developers will not help you with this. For profit, you should look towards applications in the Chrome Web Store.
- For Chrome, you need to think about advertising somewhere on the side. Otherwise, no one will know about your wonderful extension.
Links: version for Opera , for Chrome , source code .
UPD: Wimsey clarifies that there are auto- updates in Opera. The text is corrected.