Level of control in browser add-on code: How low can I go?

39 views Asked by At

Never having written a browser add-on, it's difficult for me to phrase this question concisely (and search for existing work). When viewing a news media site, when I click on the link to a news story, I would like to see only the text of the news article and prevent the browser from accessing any other URL in the story's source page, including pictures, videos and ads. I can do this in a terminal window with a Perl script: issue a get on the URL, find the story by analyzing the HTML, extract and print it -- or, as a CGI script, to a browser window. The functionally equivalent browser add-on would say, in effect, don't grab that URL I just clicked on, let me get it, let me parse the page that's returned, and let me build my display of its contents with my own priorities. Does the browser add-on model provide for this level of control? If so, where's a good primer for a newbie?

1

There are 1 answers

0
bluehexagons On

The short answer is: yes.

If you are interested in making a Firefox/Chrome add-on you would be using JavaScript, which is a very powerful language. Anything you could do in JavaScript on the web page, plus much more when using browser-specific extension APIs, is possible in an add-on. If you aren't already familiar with JavaScript, my personal recommendation for learning is the Mozilla Developer Network. One approach for what you want to do would be to find anchor tags that link to articles, then add click event listeners to them that would start the routine you want (likely download the HTML using XMLHttpRequest or the 'fetch' API) and prevent the default behavior of following the link.